The problem is where you put the snd t1
.
foldr (.) (snd t1) (foldr (++) [] (map trd3 (snd t2)))
Let's pretend for a moment that this type checked, then this would evaluate to
f3 . f2 . f1 . snd t1
which is nonsense because snd t1
isn't a function, so you can't compose it.
What you want to do is to first compose the functions, then apply the resulting function to snd t1
. You can do this by using id
as the second argument to foldr
, i.e.
foldr (.) id (foldr (++) [] (map trd3 (snd t2))) $ snd t1
which evaluates to
f3 . f2 . f1 . id $ snd t1
which is of course the same as
f3 . f2 . f1 $ snd t1
which is what you wanted.