[Haskell-cafe] Getting the x out

michael rice nowgate at yahoo.com
Tue Apr 21 20:49:02 EDT 2009


How do I get the x out of Just x?

Michael

=============

safeDivision :: Float -> Float -> Maybe Float 
safeDivision x y = if y == 0 then Nothing else Just (x/y)

*Main Data.List> safeDivision 10 5
Just 2.0
*Main Data.List> 3 + (safeDivision 10 5)

<interactive>:1:0:
    No instance for (Num (Maybe Float))
      arising from a use of `+' at <interactive>:1:0-22
    Possible fix: add an instance declaration for (Num (Maybe Float))
    In the expression: 3 + (safeDivision 10 5)
    In the definition of `it': it = 3 + (safeDivision 10 5)
*Main Data.List> 




      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090421/b73aff9b/attachment.htm


More information about the Haskell-Cafe mailing list