<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Got it! I figured there must be some way to unpack it.<br><br>My goodness, there are so many functions I'm not even aware of. Has anyone ever counted them all?<br><br>Thanks.<br><br>Michael<br><br>--- On <b>Tue, 4/21/09, Tony Morris <i>&lt;tonymorris@gmail.com&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Tony Morris &lt;tonymorris@gmail.com&gt;<br>Subject: Re: [Haskell-cafe] Getting the x out<br>To: "michael rice" &lt;nowgate@yahoo.com&gt;<br>Cc: haskell-cafe@haskell.org<br>Date: Tuesday, April 21, 2009, 8:54 PM<br><br><div class="plainMail">You mean, the x out of *Maybe* x even. In the very literal sense, the<br>assumption that there is an x in "Maybe x" is false -- there may not be<br>one since it is maybe, but not necessarily, x. IT's a bit like the use<br>of null that you
 might have seen in other languages where you might have<br>a value or you might have null. What you can do however, is say "give me<br>the x if there is one, otherwise, use this value".<br><br>This is the fromMaybe function.<br><br>Prelude Data.Maybe&gt; let safeDivision x y = if y == 0 then Nothing else<br>Just (x/y)<br>Prelude Data.Maybe&gt; 3 + (42 `fromMaybe` safeDivision 10 5)<br>5.0<br>Prelude Data.Maybe&gt; 3 + (42 `fromMaybe` safeDivision 10 0)<br>45.0<br><br><br><br>michael rice wrote:<br>&gt; How do I get the x out of Just x?<br>&gt;<br>&gt; Michael<br>&gt;<br>&gt; =============<br>&gt;<br>&gt; safeDivision :: Float -&gt; Float -&gt; Maybe Float<br>&gt; safeDivision x y = if y == 0 then Nothing else Just (x/y)<br>&gt;<br>&gt; *Main Data.List&gt; safeDivision 10 5<br>&gt; Just 2.0<br>&gt; *Main Data.List&gt; 3 + (safeDivision 10 5)<br>&gt;<br>&gt; &lt;interactive&gt;:1:0:<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;No instance for (Num (Maybe
 Float))<br>&gt;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;arising from a use of `+' at &lt;interactive&gt;:1:0-22<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;Possible fix: add an instance declaration for (Num (Maybe Float))<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;In the expression: 3 + (safeDivision 10 5)<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp;In the definition of `it': it = 3 + (safeDivision 10 5)<br>&gt; *Main Data.List&gt;<br>&gt;<br>&gt;<br>&gt; ------------------------------------------------------------------------<br>&gt;<br>&gt; _______________________________________________<br>&gt; Haskell-Cafe mailing list<br>&gt; <a ymailto="mailto:Haskell-Cafe@haskell.org" href="/mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>&gt;&nbsp;&nbsp;&nbsp;<br><br>-- <br>Tony Morris<br><a href="http://tmorris.net/"
 target="_blank">http://tmorris.net/</a><br><br><br></div></blockquote></td></tr></table><br>