5 Nov
2003
5 Nov
'03
6:05 a.m.
In Haskell, data types and contructors must be designated by names whose first letter is capitalised. So,
data currency = ...
is illegal. Instead use,
data Currency = Dollar Double | Pound Double | Zloty Double | Euro Double
Above are four data constructors and they can be used to contruct a datum of the type Currency. They can be exploited in functions through pattern matching as follows,
toDollar :: Currency -> Currency toDollar (Pound d) = Dollar ( d / 2 ) toDollar (Euro d) = Dollar ( d / 1.01 ) ...
I think, to answer your last question, that they are functions, however they can only be defined using a much more limited syntax. I'm sure someone else can give a fuller answer here. Tom
8333
Age (days ago)
8333
Last active (days ago)
0 comments
1 participants
participants (1)
-
Thomas L. Bevan