[Haskell-cafe] Re: [Haskell] [newbye] 'Just a'
GK at ninebynine.org
Mon Feb 7 10:08:56 EST 2005
[I've switched my response to the Haskell-cafe list]
What do you intend if both (get a) and (get b) return Nothing?
You might also be interested in the library function 'maybe':
or maybe (sic) Maybe.fromMaybe in:
Using one of these, I think your function could reasonably be expressed as
a simple one-liner.
At 19:33 04/02/05 +0100, Yuri D'Elia wrote:
>Hi all. I'm experimenting with haskell and its type system.
>I've done a function which scans a list, and returns "Just a"
>value if the element is found, or Nothing.
>get :: a -> Maybe a
>getAorB :: Maybe a -> Maybe a -> a
>getAorB a b = ...
>a function which returns "Just (get a)" or "Just (get b)" if (get a) is
>Nothing (excluding failures in both). By now, I've implemented it in
>terms of pattern matching:
>getAorB a b = f (get a) (get b)
> where f (Just a) Nothing = a
> f Nothing (Just a) = a
>but I'd like to know if there are other possible ways to do it, possibly
>without enforcing an evaluation order like pattern matching does.
>Haskell mailing list
>Haskell at haskell.org
More information about the Haskell-Cafe