[Haskell] lazy constructors

Sander Evers s.evers at cs.ru.nl
Wed Oct 13 04:13:58 EDT 2004


>Question 2
>----------
>How to arrange the above `lazy' output?
>  
>
Your function addToSPair

addToSPair :: Char -> (String, String) -> (String, String)
addToSPair    c       (xs,     ys    ) =  (c:xs,   ys    )

does a strict pattern match on the pair constructor. It needs to know
that its second argument is a pair before it produces anything of its
result. If you use a lazy pattern match

addToSPair :: Char -> (String, String) -> (String, String)
addToSPair    c       ~(xs,     ys    ) =  (c:xs,   ys    )

instead, it doesn't need to evaluate this argument immediately.
Regards,

Sander




More information about the Haskell mailing list