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

Ryan Ingram ryani.spam at gmail.com
Tue May 26 17:12:14 EDT 2009


This is related to the long thread on a bug in cross-module strictness
analysis for the "lazy" function in GHC.

Simon posted a response to that bug (
http://hackage.haskell.org/trac/ghc/ticket/3259 ), which shows the
Haskell source for GHC's "par" function:

> {-# INLINE par  #-}
> par :: a -> b -> b
> par  x y = case (par# x) of { _ -> lazy y }

While I understand that in GHC Core, case always reduces its argument
to WHNF, this isn't true of Haskell in general.  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?

  -- ryan

On Tue, May 26, 2009 at 10:29 AM, Duncan Coutts
<duncan.coutts at worc.ox.ac.uk> wrote:
> On Mon, 2009-05-25 at 09:40 -0400, Mario Blazevic wrote:
>> >> $diff main.simpl imported.simpl
>> >> ...
>> >> 223c232
>> >> <       a_s1rs [ALWAYS Just L] :: GHC.Integer.Internals.Integer
>> >> ---
>> >>>       a_s1sV [ALWAYS Just S] :: GHC.Integer.Internals.Integer
>> >> ...
>> >
>> > Good find!
>> >
>> >> Does this S vs. L difference have anything to do with strictness and laziness?
>> >
>> > Yes.
>> >
>> > So, I think we should open a ghc but report with all the details,
>> > particularly the example's source, the ghc version and that highlight of
>> > that strictness difference.
>
>>       I have logged the ticket at
>>
>> http://hackage.haskell.org/trac/ghc/ticket/3259
>
> Thanks for being so persistent Mario!
>
> Simon has diagnosed the bug. It's really rather subtle.
>
> Duncan
>
> _______________________________________________
> 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