Consider this code:

On 27 February 2011 05:46, Adam Megacz <[email protected]> wrote:
>   let x = escrut
>     in case x of
>       Foo a b -> ebranch1

This allocates a thunk for escrut then immediately case scrutinises
that thunk, forcing it

However, this code:

case x@escrut {
    Foo a b -> ebranch1
  }

(Where x is the case scrutinee binder) just enteres the code for
escrut with a scrutinisation frame on the stack, with no intermediate
heap allocation. Thus this code is faster.

So having the case wildcard lets GHC generate better code. Another
reason is if GHC sees:

case x@escrut {
  Foo a b -> ... Foo a b ...
}

It can rewrite the (Foo a b) it sees in the branch as x directly,
without having to go back and introduce a let-binding for escrut
before the case expression. So it is more convenient to prevent
reboxing when you have the scrutinee binder.

I'm sure Simon will have some other reasons it is good, but those are
the 2 that come to mind.

Cheers,
Max

_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to