
Thanks Don, Is your explanation specific to maybe? Or does that apply to all functions? Suppose the following function for lists: f :: [a] -> b -> (a -> [a] -> b) -> b ...instead of pattern matching [] and (x:xs) Tony Morris http://tmorris.net/ Donald Bruce Stewart wrote:
tmorris:
When you you use maybe :: b -> (a -> b) -> Maybe a -> b instead of pattern matching a returned Maybe value?
Is there something a bit more concrete on this issue?
You mean, versus using 'case' or sugar for case? It'll just inline to the same code.
For example:
maybe 10 (\n -> n + 1) bigexpr
=> {inline maybe}
(\n f x -> case x of Nothing -> n Just x -> f x) 10 (\n -> n + 1) bigexpr
=> {reduce}
case bigexpr of Nothing -> 10 Just x -> x+1
So use 'maybe' if its clearer -- it doesn't cost anything.
-- Don