Unit unboxed tuples
Roman Leshchinskiy
rl at cse.unsw.edu.au
Wed Jan 11 22:38:26 CET 2012
On 11/01/2012, at 19:28, Dan Doel wrote:
> Then I'm afraid I still don't understand the difference. Is it that
> case in core always evaluates? So:
>
> case undefined of x -> ...
>
> blows up, while
>
> case (# undefined #) of (# x #) -> ...
>
> does not?
Yes.
> Also, if so, how is (core-wise):
>
> foo :: ... -> (# T #)
> case foo <v> of (# x #) -> ...
>
> different from:
>
> foo :: ... -> T
> let x = foo <v> in ...
>
> Stack vs. heap allocation?
The second version binds x to a thunk that, when evaluated, calls foo <v> (which yields an evaluated T). The first one calls foo <v> and then binds x to whatever T (possibly unevaluated) it returns.
It really is exactly the same as:
data Box a = Box a
foo :: ... -> Box T
case foo <v> of Box x -> ...
vs.
foo :: ... -> T
let x = foo <v> in ...
Except that Box T is lifted and (# T #) isn't.
Roman
More information about the Glasgow-haskell-users
mailing list