[Haskell-cafe] Getting the x out
michael rice
nowgate at yahoo.com
Wed Apr 22 08:59:47 EDT 2009
It makes sense, once you understand the terminology.
Thanks.
Michael
--- On Wed, 4/22/09, Cristiano Paris <frodo at theshire.org> wrote:
From: Cristiano Paris <frodo at theshire.org>
Subject: Re: [Haskell-cafe] Getting the x out
To: "michael rice" <nowgate at yahoo.com>
Cc: haskell-cafe at haskell.org
Date: Wednesday, April 22, 2009, 7:55 AM
On Wed, Apr 22, 2009 at 2:49 AM, michael rice <nowgate at yahoo.com> wrote:
> How do I get the x out of Just x?
Hi Michael,
in your code you're using Maybe to inform the caller of safeDivision
about an exceptional situation. This way, you made a full coverage of
all the input cases and nothing is left out, i.e. you created a total
function (which is GOOD).
If you introduced the Nothing case, you just don't want to ignore it.
Also, the type system is forcing you to take the Nothing case into
account so you can handle it properly. Hence, you might try something
like the "maybe" function, which accounts for the Nothing case.
If you'd use fromJust, the Nothing case would remain uncovered,
leading you to an unhandled exception, which conflicts with your
safeDivision definition.
Cristiano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090422/26d69e38/attachment.htm
More information about the Haskell-Cafe
mailing list