[Haskell-cafe] Getting the x out
Cristiano Paris
frodo at theshire.org
Wed Apr 22 07:55:27 EDT 2009
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
More information about the Haskell-Cafe
mailing list