<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">If you want to just get the value out, meaning you'll get a program error if it happens to be Nothing, then you can use Data.Maybe.fromJust. But usually, you'd want to preserve the Nothing. Applicative or Monad is pretty good for this:<div><br></div><div>import Control.Applicative</div><div><br></div><div>(3+) &lt;$&gt; safeDivision 10 5</div><div><br></div><div>the result will be Just 5.0 in this case, but if the division was incorrect it would be nothing.</div><div><br></div><div>If you want to do something else, you can either pattern match on it:</div><div><br></div><div>case safeDivision 10 5 of</div><div>&nbsp;&nbsp;Just x -&gt; -- do something with x</div><div>&nbsp;&nbsp;Nothing -&gt; -- do something else</div><div><br></div><div>or use some functions from Data.Maybe. Say you want to evaluate to 1 instead of Nothing:</div><div><br></div><div>import Data.Maybe</div><div><br></div><div>fromMaybe 1 (safeDivision 10 5)</div><div><br></div><div>-Ross</div><div><br></div><div><div><div><div>On Apr 21, 2009, at 8:49 PM, michael rice wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font: inherit;">How do I get the x out of Just x?<br><br>Michael<br><br>=============<br><br>safeDivision :: Float -&gt; Float -&gt; Maybe Float <br>safeDivision x y = if y == 0 then Nothing else Just (x/y)<br><br>*Main Data.List&gt; safeDivision 10 5<br>Just 2.0<br>*Main Data.List&gt; 3 + (safeDivision 10 5)<br><br>&lt;interactive&gt;:1:0:<br>&nbsp;&nbsp;&nbsp; No instance for (Num (Maybe Float))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arising from a use of `+' at &lt;interactive&gt;:1:0-22<br>&nbsp;&nbsp;&nbsp; Possible fix: add an instance declaration for (Num (Maybe Float))<br>&nbsp;&nbsp;&nbsp; In the expression: 3 + (safeDivision 10 5)<br>&nbsp;&nbsp;&nbsp; In the definition of `it': it = 3 + (safeDivision 10 5)<br>*Main Data.List&gt; <br><br></td></tr></tbody></table><br>       _______________________________________________<br>Haskell-Cafe mailing list<br><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>http://www.haskell.org/mailman/listinfo/haskell-cafe<br></blockquote></div><br></div></div></body></html>