In my quest to re-learn Haskell I eventually thought: “OK, let’s see how an exception looks like”. Starting my favorite interactive Haskell implementation:
___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 6.4.1, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help. Loading package base-1.0 ... linking ... done. Prelude>
OK. Let’s generate an exception now, a division by zero for example (something basic):
Prelude> 1 / 0 Infinity
Woa! Infinity ? Programming languages were not supposed to know about such things. Is it a real concept of Infinity or just a little label:
Prelude> (1 / 0) * 5 Infinity
OK, so far, it behaves good. Diving infinity by infinity is even more invalid that dividing one by zero, that surely has to raise an exception:
Prelude> (1 / 0) / (1 / 0) NaN
Not A Number ? mmmhhh… My quest for an exception failed, back to the gentle guide (and thinking how GUIs and statistics programs would output the correct ‘values’ Inifinity and NaN to the user without a long sets of ifs)
Leave a Reply