While reading Real world Haskell I came up with this note:
ghci> :info (+)
class (Eq a, Show a) => Num a where
(+) :: a -> a -> a
...
-- Defined in GHC.Num
infixl 6 +
But how can Haskell define + as a non-native function? At some level you have to say that 2 + 3 will become assembler i.e. machine code.
The
+function is overloaded and for some types, likeIntandDoublethe definition of+is something likewhere
primAddIntis a function the compiler knows about and will generate machine code for.The details of how this looks and works depends on the Haskell implementation you’re looking at.