このタイプの同義語を考えると:
type Synonym a b = (a, b)
このコードはGHCiでは機能しません:
ghci> let myFirst (f, s) = f :: Synonym a b -> a
<interactive>:1:21:
Inferred type is less polymorphic than expected
Quantified type variable `b' is mentioned in the environment:
f :: Synonym a b -> a (bound at <interactive>:1:13)
Quantified type variable `a' is mentioned in the environment:
f :: Synonym a b -> a (bound at <interactive>:1:13)
In the expression: f :: Synonym a b -> a
In the definition of `myFirst':
myFirst (f, s) = f :: Synonym a b -> a
しかし、これはします:
ghci> let myFirst = fst :: Synonym a b -> a
-- no problem --
これは、GHCiに直接入力した場合にのみ発生します。両方の定義は、ファイルとそれらに入れると機能し:load
ます。
ここでの問題は何ですか?私は何度もこの問題に遭遇しましたが、その理由はわかりませんでした。
ps試し:set -XNoMonomorphismRestriction
ましたが、違いはありませんでした。