Next | Atypical Types | 35 |
Numeric operations are similarly overloaded
The type of + is
(Num a) => a -> a -> a
So you can add two Integer arguments and get another Integer
Add two Float arguments and get another Float
Define your own Vector type
Declare that it's an instance of Num
Define + (and *, etc.) operations on it
And then add two Vector arguments and get another Vector
But if you mess up and add a Vector to an Integer you'll get a compile-time error
Next | Copyright © 1999,2008 Mark Dominus |