Je ne comprends pas pourquoi la fonction suivante fonctionne:Confusion avec inférence de type Haskell
isLongerThanN :: Integral n => n -> [a] -> Bool
isLongerThanN n xs = length xs > fromIntegral n
mais les suivantes ne:
isLongerThanN' :: Integral n => n -> [a] -> Bool
isLongerThanN' n xs = length xs > n
qui jette l'erreur
Could not deduce (n ~ Int)
from the context (Integral n)
bound by the type signature for
isLongerThanN' :: Integral n => n -> [a] -> Bool
at blah.hs:140:1-35
`n' is a rigid type variable bound by
the type signature for
isLongerThanN' :: Integral n => n -> [a] -> Bool
at blah.hs:140:1
In the second argument of `(>)', namely `n'
In the expression: length xs > n
In an equation for `isLongerThanN'':
isLongerThanN' n xs = length xs > n
(que j'ai probablement mal compris)
Si quelque chose, je m'attendrais à ce que ce soit l'inverse, puisque fromIntegral élargit effectivement le type variable n.
Ne pas écrire 'si foo puis Vrai autre FALSE'. C'est la même chose que "foo". – hammar
vous avez raison, merci; Je l'ai modifié, mais ce n'est pas la question – Inept
C'est pourquoi il ne l'a pas posté comme réponse ... – Jasper