[Haskell-cafe] CPS versus Pattern Matching performance

Donald Bruce Stewart dons at cse.unsw.edu.au
Tue Jul 10 04:04:32 EDT 2007


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


More information about the Haskell-Cafe mailing list