Non capisco il motivo per cui la seguente funzione funziona:confusione con il tipo di Haskell inferenza
isLongerThanN :: Integral n => n -> [a] -> Bool
isLongerThanN n xs = length xs > fromIntegral n
ma la segue non:
isLongerThanN' :: Integral n => n -> [a] -> Bool
isLongerThanN' n xs = length xs > n
che genera l'errore
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
(che probabilmente ho frainteso)
Semmai, mi aspetterei che sia il contrario, dal momento che da Integrale sta effettivamente allargando il tipo della variabile n.
Non scrivere 'se foo allora Vero altro false'. È lo stesso di "pippo". – hammar
hai ragione, grazie; L'ho modificato, ma non è questa la domanda – Inept
Ecco perché non l'ha postata come risposta ... – Jasper