Strictness!

Jay Cox sqrtofone@yahoo.com
Thu, 14 Mar 2002 22:23:32 -0600 (CST)


On Thu, 14 Mar 2002, Brian Huffman wrote:

> In Haskell you can produce the desired behavior by using pattern guards.
> Since the pattern guards always get evaluated before the result does, they
> can be used to make things more strict. Here is the foldl example:
>
> strict x = seq x True
>
> foldl' :: (a -> b -> a) -> a -> [b] -> a
> foldl' f z [] = z
> foldl' f z (x:xs)
>   | strict z = foldl' f (f z x) xs
>
> You can make multiple arguments strict by using && or similar, e.g.:
>
> f x y | strict x && strict y = ...
> f x y | all strict [x,y] = ...
>
> Of course, with the second example x and y must have the same type.
> Hope this helps.
>
> - Brian Huffman

Thanks! that looks like a great haskell idiom to use!

Jay Cox