鉴于这种类型的同义词:
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
了,但这并没有什么不同。