[Haskell-cafe] Optimizing unamb by determining the "state" of a
thunk?
Peter Verswyvelen
bugfact at gmail.com
Mon Apr 20 16:54:55 EDT 2009
f `unamb` g just needs f or g to be in weak head normal form I think. This
should be much easier to test for I guess.
I always confuse weak head normal form with reduced head normal form, but
the documentation of GHC does not help here:
E.g.:
-- | Reduces its argument to weak head normal form.rwhnf :: Strategy a
rwhnf x = x `seq` ()
but the documentation of seq says
*seq* :: a -> b -> bSource
<file:///C:/app/ghc-6.10.2/doc/libraries/ghc-prim/src/GHC-Prim.html#seq>Evaluates
its first argument to head normal form, and then returns its second
argument as the result.
Furthermore:
*rnf* :: Strategy
<file:///C:/app/ghc-6.10.2/doc/libraries/parallel/Control-Parallel-Strategies.html#t%3AStrategy>
aSource <file:///C:/app/ghc-6.10.2/doc/libraries/parallel/src/Control-Parallel-Strategies.html#rnf>Reduces
its argument to (head) normal form.
So from the documentation rnf should be like seq, but it is not, rnf
is a "deep seq".
I find this very confusing. Is the documentation of seq wrong (should
be weak head normal form)?
Anyway, so I guess we would actually need a function:
iswhnf :: a -> IO Bool
But since the value of this iswhnf function depends on when it is called, I
feel it has to be in the IO monad; actually multiple threads evaluating it
have nothing to do with it?
On Mon, Apr 20, 2009 at 10:05 PM, Jake McArthur <jake.mcarthur at gmail.com>wrote:
> Christopher Lane Hinson wrote:
>
>> What we'd like to avoid is duplicate verification that a thunk is hnf. Do
>> we have evidence that this verification ever actually consumes a lot of
>> resources?
>>
>
> I think the OP is trying to avoid spawning unnecessary threads at the cost
> of duplicate checks for HNF.
>
> - Jake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090420/a17e0d2c/attachment.htm
More information about the Haskell-Cafe
mailing list