[Haskell-beginners] How do I return Nothing from a function?
dedgrant at gmail.com
Mon Apr 21 18:25:24 UTC 2014
If the result of weight is (Maybe t) instead of the then the result of the
array lookup can be passed out directly for the caller to check:
weight x y g = g!(x, y)
Is this what you mean?
On Apr 21, 2014 10:53 AM, "KC" <kc1956 at gmail.com> wrote:
> 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
> :: (Ix t1, Ix t2) => t1 -> t2 -> Array (t1, t2) (Maybe t) -> t
> weight x y g = w
> (Just w) = g!(x,y)
> Thank you for your time.
> Sent from an expensive device which will be obsolete in a few months! :D
> Beginners mailing list
> Beginners at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners