有沒有人知道爲什麼這段代碼失敗?haskell - 奇怪的模糊類型變量錯誤消息代碼在「where」語句與TypeFamilies擴展
{-# LANGUAGE NoMonomorphismRestriction,
TypeFamilies #-}
module Test where
asExprTyp :: Expr γ =>
γ α
-> α
-> γ α
asExprTyp x _ = x
int = undefined :: Integer
class Expr γ where
a :: γ α
-- this works fine
b = a `asExprTyp` int
-- this fails
mcode = do
return()
where b = a `asExprTyp` int
的錯誤如下,
Test.hs:23:15:
Ambiguous type variable `γ0' in the constraint:
(Expr γ0) arising from a use of `a'
Probable fix: add a type signature that fixes these type variable(s)
In the first argument of `asExprTyp', namely `a'
In the expression: a `asExprTyp` int
In an equation for `b': b = a `asExprTyp` int
Failed, modules loaded: none.
我在這裏沒有看到問題。你認爲'b'在失敗的表達中有什麼類型? –
@JohnL:'b :: Exprγ=>γInteger' – mergeconflict
@mergeconflict:這是完全合理的。我在考慮將γ作爲關聯類型,但它絕對不是。 –