我的职责如下:
foo :: Int -> a -> [a]
foo n v = bar n
where
bar :: Int -> [a]
bar n = take n $ repeat v
使用 ghci 报告此错误 :
Couldn t match type `a with `a1
`a is a rigid type variable bound by
the type signature for foo :: Int -> a -> [a] at hs99.hs:872:1
`a1 is a rigid type variable bound by
the type signature for bar :: Int -> [a1] at hs99.hs:875:9
Expected type: [a1]
Actual type: [a]
In the expression: take n $ repeat v
In an equation for `bar : bar n = take n $ repeat v
如果删除条形声明类型, 代码可以毫无错误地编译 。 这里的条形声明类型是什么? 为什么会发生错误, 因为条形声明类型比条形定义( 条形声明与某类相联) 更加通用?
谢谢你的帮助!