[Haskell-cafe] Partially applied functions

Casey Hawthorne caseyh at istar.ca
Sun Nov 29 15:16:53 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.


Just changed a few things.
Hopefully this answers the OP's question and any interested others.

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 pred = map (\ f -> f 10 ) (addPs pred)

-- Wanted to do things like this.
-- add3s = filter (?) adds -- add3s = [add 3, add 3]
-- addEvens = filter (?) adds --addEvens = [add 8]

-- addPs num = [ x | x <- adds, x 0 == num ]
-- Changed 'x' to 'f' indicating a function application.
addPs pred = [ f | f <- adds, pred (f 0) ]

-- Main> kP (==3)
-- Main> kP even

--
Regards,
Casey


More information about the Haskell-Cafe mailing list