Perl, Haskell, stuff
We are presented with some coercion functions and asked
It is instead defined as round(100 * x). This is because if rounding was done on the input parameter, then whether it was, say, 1.01 or 1.99, the answer would be the same: 100*(round 1.01) = 100*1 = 100.
Similarly, this is to do with fixity/order of application of expressions: The version above would first try to evaluate n/100, which will fail, as n is an Integer, and “/“ isn't defined for Ints.
That's it for the exercises. I played along with the examples, which basically amounts to copying out of the book - actually I think that's more instructive than just reading or getting the source code off the internet, because it helps develop finger-memory.
Well, he does leave a “you may wish to define these functions on your own as an exercise”, but right now, I'm going to bed instead.
Osfameron's blog on Haskell, Perl programming, stuff.
Leave a reply