
2009/3/29 Zachary Turner
The "pipelining" operator I defined should definitely be used with care. For example, it requires the pipelined argument to be the last argument, which is not always the case. And I've also found that with it I tend to think about the problem less, and write less efficient code as a result. For example given a list of integers, an easy and very readable way to remove all multiples of 2 from a list, and then double the remaining items could be like this:
let doit x = x |> filter (\y -> y `mod` 2 == 0) |> map (* 2)
as opposed to the more efficient
doit [] = [] doit (x:xs) | (x `mod` 2 == 0) = doit xs doit (x:xs) = (2 * x) : doit xs
since the list is walked twice. (I'm betting someone will respond with a cool one-liner here involving function composition or something else that I can't think of yet :)
Have you tried timing it? I'm not seeing much difference in execution speed between the two functions. Antoine