[Haskell-cafe] CPS versus Pattern Matching performance
Tony Morris
tmorris at tmorris.net
Tue Jul 10 13:20:32 EDT 2007
Thanks for the explanations - fully understood.
Tony Morris
http://tmorris.net/
Jonathan Cast wrote:
> On Tuesday 10 July 2007, Tony Morris wrote:
>> 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)
>
> Of course. GHC doesn't know anything about maybe; all it sees is:
>
> 1. One-liner:
>
> maybe f x mb = case mb of { Just x' -> f x'; Nothing -> x }
>
> 2. Non-recursive
>
> And it inlines like crazy. If you had quite a large data type, the number of
> case alternatives /might/ put you over GHC's inlining threshold, but that
> (ridiculous) scenario is the only thing that'll keep the argument from
> generalizing to your use case.
>
> <snip>
>
> Jonathan Cast
> http://sourceforge.net/projects/fid-core
> http://sourceforge.net/projects/fid-emacs
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
>
More information about the Haskell-Cafe
mailing list