Так что я только начал изучать Haskell, и я застрял в этом уже довольно давно.Поэтому у меня есть функция, которая вычисляет число после смещения минус (минимальное значение равно 0).Мне удалось выполнить эту функцию с явно указанными типами.
offSetter :: Int -> Int -> Int
offSetter number offset
| number - offset >= 0 = number - offset
| otherwise = 0
Но когда я попытался изменить ее на использование универсальных типов, как показано ниже, она продолжает выдавать ошибку.Я делаю это неправильно?
offSetter :: Num a => a -> a -> a
offSetter number offset
| number - offset >= 0 = number - offset
| otherwise = 0
Ошибка, которую я получаю:
* Could not deduce (Ord a) arising from a use of '>='
from the context: Num a
bound by the type signature for:
offSetter :: forall a. Num a => a -> a -> a
at src\test.hs:57:1-33
Possible fix:
add (Ord a) to the context of
the type signature for:
offSetter :: forall a. Num a => a -> a -> a
* In the expression: number - offset >= 0
In a stmt of a pattern guard for
an equation for `offSetter':
number - offset >= 0