I’m bit stuck how to rewrite following strict-evaluated list comprehension to use seq instead of bang pattern:
zipWith' f l1 l2 = [ f e1 e2 | (!e1, !e2) <- zip l1 l2 ]
Any idea ?
I’ve tried
zipWith' f l1 l2 = [ e1 `seq` e2 `seq` f e1 e2 | (e1, e2) <- zip l1 l2 ]
but this unfortunately does not force an evaluation to WHNF.
You can mechanically translate bang patterns into calls to
seqfollowing the GHC
manual:
This:
BecomesToo lazy:Which is more concisely written as(too lazy):Though I’d write it as(wrong, too lazy)You could also move the strictness hint to a data structure:
Or as: