私は以下のような機能を持っています:
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
bar の型宣言を削除すると、コードはエラーなしでコンパイルできます。では、ここで bar の適切な型宣言は何ですか? また、bar の型宣言は bar の定義 (foo の型にバインドされている) よりも一般的であるため、エラーが発生するのはなぜですか?
助けてくれてありがとう!