[Haskell-cafe] Function hanging in infinite input
martin.drautzburg at web.de
Sun Apr 26 19:23:56 UTC 2015
Am 04/26/2015 um 08:38 PM schrieb Matthew Korson:
> The problem is that tAppend is too strict; it evaluates both its arguments before producing anything. This is because
> you are pattern matching on those arguments. You could use lazy patterns or make Temporal a newtype to avoid that. Or
> you could rewrite to something like
> tAppend as bs = Temporal $ toList as ++ toList bs
Mathew, you made my day!
At least things work now as expected. But could you please elaborate on the difference between
tAppend (Temporal as) (Temporal bs) = Temporal (as ++ bs)
tAppend as bs = Temporal $ (toList as) ++ (toList bs)
toList (Temporal xs) = xs
Why is the first one more strict than the second?
More information about the Haskell-Cafe