Proposal: Strict scanl, scanl1 and mapAccumL

Thomas Schilling nominolo at googlemail.com
Thu Nov 15 16:46:53 CET 2012


Yes, GHC will rewrite this to

    force x = x

I'm also not sure if we really want "seq" in all of these cases, or if we
want stronger guarantees.  For example, GHC can (and often will) rewrite

    f x y = x `seq` y `seq` x

to

    f x y = y `seq` x

This changes the order of evaluation. For pure computations this is
semantically sound. However, it can change the space behaviour of the
program, which defeats the point of using "seq" in the first place
(usually). If forcing "x" to be evaluated before "y" is the goal, then
"pseq" must be used. I think it's worthwhile to consider introducing
high-level combinators for this use case as well.


On 15 November 2012 15:38, Johan Tibell <johan.tibell at gmail.com> wrote:

> On Thu, Nov 15, 2012 at 2:38 AM, Henning Thielemann <
> lemming at henning-thielemann.de> wrote:
>
>>  On Mon, 12 Nov 2012, Bas van Dijk wrote:
>>
>>> force :: WHNFData a => a -> a
>>> force x = x `seq` x
>>>
>>
>> Does this function do something?
>>
>
> No. It says "when x is evaluated, evaluate x".
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
>


-- 
Push the envelope. Watch it bend.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20121115/960c05fd/attachment.htm>


More information about the Libraries mailing list