[Haskell-beginners] How do I return Nothing from a function?

Norbert Melzer timmelzer at gmail.com
Mon Apr 21 18:23:44 UTC 2014


You can't return Nothing, because your function doesn't return a maybe. If
you make it a maybe, you just need to return the value of g without further
processing.
Am 21.04.2014 19:53 schrieb "KC" <kc1956 at gmail.com>:

> How do I return Nothing from a function?
>
> When there is no edge in the graph this code fails.
> *** Exception: Graph.hs:65:9-26: Irrefutable pattern failed for pattern
> (Data.Maybe.Just w)
>
>
> *Main> :t weight
> weight
>   :: (Ix t1, Ix t2) => t1 -> t2 -> Array (t1, t2) (Maybe t) -> t
>
> weight x y g = w
>     where
>         (Just w) = g!(x,y)
>
>
> Thank you for your time.
>
> --
>
> --
>
> Sent from an expensive device which will be obsolete in a few months! :D
> Casey
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140421/dfe0c982/attachment.html>


More information about the Beginners mailing list