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.
/ /_\\/ __  / /___| |      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)

Advertisements

2 Replies to “Trying to find exceptions in Haskell”

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s