【发布时间】:2019-02-25 03:57:21
【问题描述】:
Haskell 的类型系统存在以下问题:我试图声明一个数据类型并从函数返回一个包含该类型元素的列表。不幸的是,即使是最小的测试用例,例如
data SampleType = SampleTypeConstructor
instance Show SampleType where
show x = "(SampleType)"
stList :: (Show a) => [a]
stList = [(SampleTypeConstructor)]
main = do {
putStrLn (show stList)
}
失败,来自 ghc-7.0.2 和 ghc-7.1.20110327 的错误消息如下:
tcase.hs:7:12:
Could not deduce (a ~ SampleType)
from the context (Show a)
bound by the type signature for stList :: Show a => [a]
at tcase.hs:7:1-34
`a' is a rigid type variable bound by
the type signature for stList :: Show a => [a] at tcase.hs:7:1
In the expression: (SampleTypeConstructor)
In the expression: [(SampleTypeConstructor)]
In an equation for `stList': stList = [(SampleTypeConstructor)]
【问题讨论】: