[Haskell-cafe] Function hanging in infinite input
Brandon Allbery
allbery.b at gmail.com
Sun Apr 26 19:43:35 UTC 2015
On Sun, Apr 26, 2015 at 3:23 PM, martin <martin.drautzburg at web.de> wrote:
> At least things work now as expected. But could you please elaborate on
> the difference between
>
> tAppend (Temporal as) (Temporal bs) = Temporal (as ++ bs)
>
> vs
>
> tAppend as bs = Temporal $ (toList as) ++ (toList bs)
> toList (Temporal xs) = xs
>
> Why is the first one more strict than the second?
>
Because the first one pattern matches both parameters immediately to ensure
that the constructor is the one named (Temporal). The second defers it,
since the toList call is not forced and therefore won't be invoked (along
with its strict pattern match) until its value is needed.
--
brandon s allbery kf8nh sine nomine associates
allbery.b at gmail.com ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150426/1afa9d52/attachment.html>
More information about the Haskell-Cafe
mailing list