関数型プログラミング言語Haskell Part5
■ このスレッドは過去ログ倉庫に格納されています
0826デフォルトの名無しさん
2006/10/16(月) 23:38:22f :: (Num a) => (a -> a) -> a
f k = g 10
where
g :: (Num a) => a -> a
g = k
main = print $ f id
GHCでコンパイルすると、下のようなエラーになってしまいます
(gの型を明示的に書かなければコンパイルできます)。
「gの型のaは、fのaと同じ」ということが記述できれば解決するような
気がするのですが、なにかうまい方法はありますでしょうか?
where節の関数の型は書かないのが普通なのでしょうか?
test.hs:6:2:
Inferred type is less polymorphic than expected
Quantified type variable `a' is mentioned in the environment:
k :: a -> a (bound at test.hs:3:2)
When trying to generalise the type inferred for `g'
Signature type: forall a. (Num a) => a -> a
Type to generalise: a -> a
In the type signature for `g'
When generalising the type(s) for `g'
■ このスレッドは過去ログ倉庫に格納されています