[Haskell-cafe] How does GHC's implementation of par work?

Max Bolingbroke batterseapower at hotmail.com
Tue May 26 20:32:35 EDT 2009


2009/5/26 Ryan Ingram <ryani.spam at gmail.com>:
> What causes par# to
> get executed?  Does GHC overload case for unboxed return values to
> force the evaluation of the scrutinee even if its return value isn't
> used?

As you noted, the type of "par" is a -> Int#. Furthermore, the only
possible evaluation semantics for unboxed types in GHC's intermediate
language is strict. This means that your case expression has to
evaluate the scrutinee eagerly.

Indeed, consider the following program (which looks even lazier than
your example):

let x :: Int# = error "boom!"
in 10

This will diverge in either Haskell or Core, because both languages
promise that if have an unlifted thing in your environment /it really
has been evaluated/. SPJ and I recently wrote a paper [1] proposing an
intermediate language for GHC that would allow Core to express thunks
of unlifted types, but even so I don't think we would actually want to
change the semantics of bindings of unlifted types in Haskell.

Cheers,
Max

[1] http://www.cl.cam.ac.uk/~mb566/papers/tacc-hs09.pdf


More information about the Haskell-Cafe mailing list