[Haskell-cafe] Partially applied functions
Casey Hawthorne
caseyh at istar.ca
Sat Nov 28 17:55:57 EST 2009
You can pattern match on the right hand side of '|' in a list
comprehension, since a list comprehension is just the list monad.
add :: Int -> Int -> Int
add x y = x + y
-- a list of partially applied functions
adds = [add 3, add 5, add 7, add 3, add 5, add 8]
-- an example usage of the list
kP num = map (\ f -> f 10 ) (addPs num)
-- add3s = filter (?) adds -- add3s = [add 3, add 3]
-- addEvens = filter (?) adds --addEvens = [add 8]
addPs num = [ x | x <- adds, x 0 == num ]
--
Regards,
Casey
More information about the Haskell-Cafe
mailing list