Est-ce que quelqu'un sait pourquoi ce code a échoué?haskell - message d'erreur de type ambigu de type ambigu pour le code dans l'instruction "where" avec l'extension 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
L'erreur est la suivante,
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.
Je ne vois pas de problème ici. Quel type attendez-vous de 'b' dans l'expression défaillante? –
@JohnL: 'b :: Expr γ => γ Entier' – mergeconflict
@mergeconflict: c'est parfaitement raisonnable. Je pensais à γ comme un type associé, ce qui n'est certainement pas le cas. –