I\'m having some trouble with performing simple addition, subtraction -- any kind of algebra really with Haskells newtype.
My definition is (show included so I can p
You're missing a instance of how your money can add together, the clue was in the error Instance : Num Money
.
So for addition in Haskell the Num
type what is needed to add two things together as long you are dealing with numbers so let's make an instance of Num
on Money
:
newtype Money =
Money Integer deriving Show
instance Num Money where
Money a + Money b = Money $ a + b
-- Money 1 + Money 2 == Money 3
Notice that it returns Money
, will let you research how you can get the number out of the type :)