私は最近haskellで遊び始めましたが、このおもちゃの例で説明できるHashMapの使用中に問題が発生しました。
import Data.HashMap as HashMap
foo = HashMap.insert 42 53 HashMap.empty
インタプリタにファイルをロードしたり、コンパイルしたりすると、次のエラーが発生します。
Prelude List HashMap> :load TypeError.hs
[1 of 1] Compiling Main ( TypeError.hs, interpreted )
TypeError.hs:3:22:
Ambiguous type variable `k0' in the constraints:
(Num k0) arising from the literal `42' at TypeError.hs:3:22-23
(Ord k0) arising from a use of `insert' at TypeError.hs:3:7-20
(Data.Hashable.Hashable k0)
arising from a use of `insert' at TypeError.hs:3:7-20
Possible cause: the monomorphism restriction applied to the following:
foo :: Map k0 Integer (bound at TypeError.hs:3:1)
Probable fix: give these definition(s) an explicit type signature
or use -XNoMonomorphismRestriction
In the first argument of `insert', namely `42'
In the expression: insert 42 53 empty
In an equation for `foo': foo = insert 42 53 empty
Failed, modules loaded: none.
Prelude List HashMap>
ただし、インタプリタでまったく同じ関数を直接定義しても、エラーは発生しません。
Prelude List HashMap> let foo = HashMap.insert 42 53 HashMap.empty
Prelude List HashMap>
誰かがこれについて何か手がかりを持っていますか?
ありがとう。