Я не понимаю, почему следующая функция работает:Путаница с умозаключения типа Haskell
isLongerThanN :: Integral n => n -> [a] -> Bool
isLongerThanN n xs = length xs > fromIntegral n
но следующий не будет:
isLongerThanN' :: Integral n => n -> [a] -> Bool
isLongerThanN' n xs = length xs > n
, который бросает ошибку
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
(что я, вероятно, неправильно понял)
Во всяком случае, я ожидаю, что это будет наоборот, поскольку fromIntegral эффективно расширяет тип переменной n.
Не пишите 'если Foo то правда еще false'. Это то же самое, что просто 'foo'. – hammar
вы правы, спасибо; Я изменил его, но это не вопрос – Inept
Вот почему он не опубликовал его как ответ ... – Jasper