As far as I understand, both methods do the same.
nearly; with the exception of:
\> zip' undefined [] -- 1st definition of zip' [] \> zip' (filter (< 4) [1..]) [1, 2, 3] [(1,1),(2,2),(3,3)]
then:
\> zip' undefined [] -- 2nd definition of zip' *** Exception: Prelude.undefined \> zip' (filter (< 4) [1..]) [1, 2, 3] [(1,1),(2,2),(3,3) -- gets stuck here; never returns
In other words, the second definition always forces a weak head normal form for both arguments.
In terms of performance, this means that it is possible to construct such a pathological example that WHNF involves heavy calculations, so one definition is performed very differently than another.
behzad.nouri
source share