hi guys. As I know if we have type class A with a function f
class A a where
f :: a -> a -> a
and a type class B with a function g that uses f under the hood
class B b where
g :: b -> b -> b
g = f
we can’t use f here, since we just don’t have an access to f, thus,
we have to add constraint, right? Right!
class A b => B b where
g :: b -> b -> b
g = f
Then why Int8 implementation for Num uses function from Ord type class if the Num doesn’t specify anywhere that we are using Ord?
instance Num Int8 where
...
abs x | x >= 0 = x
| otherwise = negate x
...
I would understand if abs was written like
abs n = if n `geInt8#` 0 then n else negate n
The same I see for Enum
...
toEnum i@(I# i#)
| i >= fromIntegral (minBound::Int8) && i <= fromIntegral (maxBound::Int8)
= I8# (intToInt8# I#)
...
Can you please help me? Maybe I missed or forgot or just don’t know something. Thanks in advance!