bang patterns give fundamentally new capabilities?

Tomasz Zielonka tomasz.zielonka at gmail.com
Fri Dec 1 00:30:41 EST 2006


On Thu, Nov 30, 2006 at 08:13:13PM -0800, John Meacham wrote:
> I was recently presented with the problem of writing a function like so
> 
> seqInt__ :: forall a . a -> Int# -> Int#
> seqInt__ x y = x `seq` y
> 
> which seems fine, except 'seq' of type forall a b . a -> b -> b cannot
> be applied to an unboxed value.
> 
> I could not think of a way to actually get the behavior

How about something like this:

seqInt__ :: forall a . a -> Int# -> Int#
seqInt__ x y =
    case x `seq` (I# y) of
        (I# y') -> y'

The question is: will GHC optimize out the unneccesary boxing and
unboxing? Looking at the output from "ghc -O2 -ddump-simpl" makes me
think the answer is "yes".

Best regards
Tomasz


More information about the Glasgow-haskell-users mailing list