How do we know if a typeclass is a sub
If we do let add ab = a+b
then add :: Num a => a -> a -> a
.
We also know that 1.5 :: Fractional a => a
. And add 1 1.5
works flawlessly.
If I understand correctly every type which has an instance of Fractional
has also an instance of Num
, but how is this fact made explicit?
It's in the definition of the Fractional
class:
class Num a => Fractional a where
...
You can see it typing :i Fractional
in GHCi, or on the Haddock docs.
下一篇: 我们如何知道类型类是否是一个子类?