
22 May
2003
22 May
'03
3:24 p.m.
Hi all, I want to create a function that creates a cascade of function applications: cascade [ f1, f2, f3 ] x == (f3 . f2 . f1) x It's a bit trivial, but it makes implementing flowgraphs (which are usually drawn left-to-right) a bit easier. I plan on profiling this, but which of the following do you think is the most efficient implementation:
cascade1 :: Num a => [[a] -> [a]] -> [a] -> [a] cascade1 [] = \x -> x cascade1 (f:fs) = cascade1 fs . f
cascade2 :: Num a => [[a] -> [a]] -> [a] -> [a] cascade2 cs = foldr (.) (\x -> x) (reverse cs)
cascade3 :: Num a => [[a] -> [a]] -> [a] -> [a] cascade3 cs = foldl (.) (\x -> x) (reverse cs)
Thanks.
--
Matthew Donadio