Jay Cox <[EMAIL PROTECTED]> writes: > 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
I also like this for trace: f x y | trace (show (x, y)) True = ... (Putting the trace on a separate line like that makes it easy to comment out.) Or, if you've got a function with a lot of cases, you can trace all of them by adding: f x y | trace (show (x, y)) False = undefined above all the other cases. Carl Witty _______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell