From ghci:
Prelude> :i Num
class Num a where
(+) :: a -> a -> a
(-) :: a -> a -> a
(*) :: a -> a -> a
negate :: a -> a
abs :: a -> a
signum :: a -> a
fromInteger :: Integer -> a
-- Defined in `GHC.Num'
instance Num Word -- Defined in `GHC.Num'
instance Num Integer -- Defined in `GHC.Num'
instance Num Int -- Defined in `GHC.Num'
instance Num Float -- Defined in `GHC.Float'
instance Num Double -- Defined in `GHC.Float'
Why is (+)
, (-)
part of the Num class to begin with?
For example - you could easily define this type class:
class Plus a where
(+) :: a -> a -> a
And then let:
instance Plus [] where
(+) = (++)
And you could also define these for sets to mean set union, or add (-)
to a type class to mean set difference... And it makes no sense to define signum
on a list.
Of course I could create my own type class that uses (|+|)
instead
- but why was these operators reserved in haskell for Num alone?
So why was this choice made? Is it due to legacy or has no one wanted this?