3 ms·
>In math, "5" is all of those things simultaneously, but in Haskell it can only be one at a time. How is that? Excerpts from ghci dialog: Prelude> :t 5 5
by thesz 16y ago
>In math, "5" is all of those things simultaneously, but in Haskell it can only be one at a time.
How is that?
Excerpts from ghci dialog:
Prelude> :t 5
5 :: (Num t) => t
class (Num a) => Fractional a where
(/) :: a -> a -> a
recip :: a -> a
fromRational :: Rational -> a
Prelude Data.Complex> :i RealFrac
class (Real a, Fractional a) => RealFrac a where
...
Prelude Data.Complex> :i RealFloat
class (RealFrac a, Floating a) => RealFloat a where
...
Prelude Data.Complex> :i Complex
data (RealFloat a) => Complex a = !a :+ !a
instance (RealFloat a) => Eq (Complex a)
So, 5 is an Int, Integer, Rational, Double and Complex (which, actually, could be Complex Int or Complex Double).
- Zaak 16y ago(Num t) => t means that the value can have the type of any member of class Num, but it can't be more than one type at a time. There are no subtypes in Haskell.