Im trying to evaluate manually fc [f1, f2] (\x -> 2) 3
but I don't realize how to match the three parameters: [f1, f2], (\x -> 2) and 3 with the function definition, any help?
The function definition:
fc xss = \f -> let ope x y = x . f . y in foldr1 ope xss
f1, f2 :: Int -> Bool
f1 x = (x `mod` 3) == 0
f2 x = (x `mod` 5) == 0
Thanks,
Sebastián.
Well, first do some η-expansion
fc :: [a->b] -> (b->a) -> a->b
fc xss f = let ope x y = x . f . y in \q -> foldr1 ope xss q
fc xss f q = let ope x y = x . f . y in foldr1 ope xss q
Then perhaps inline the let
fc xss f q = foldr1 (\x y -> x . f . y) xss q
You can write [f1, f2]
as (==0).(`mod`3) : (==0).(`mod`5) : []
.
Now it should be easy enough, remembering that a right-fold simply replaces all :
with the fold function.