Trying to find exceptions in Haskell

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.
/ /_\\/ __  / /___| |
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base-1.0 ... linking ... done.

OK. Let’s generate an exception now, a division by zero for example (something basic):

Prelude> 1 / 0

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

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)

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)

2 thoughts on “Trying to find exceptions in Haskell

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.