0

I'm trying to manually derive the type of (foldr (.))

foldr :: (a1 -> b1 -> b1) -> b1 -> [a1] -> b1
(.) ::(b2 -> c2) -> (a2 -> b2) -> a2 -> c2

Then:

a1 ~ (b2 -> c2)
b1 ~ (a2 -> b2)
b1 ~ a2

So I get that (foldr (.)) :: (a2 -> b2) -> [(b2 -> c2)] -> (a2 -> b2)

But GHCi returns: :t (foldr (.)) :: (a -> b) -> [b -> b] -> a -> b

Why b2 and c2 are the same?

Thanks,
Sebastián.

2
  • You realise you're contradicting yourself with b1 ~ (a2 -> b2)b1 ~ a2? (Actually it's not really contradiction, but it'd be an "infinite type" which you can't have in Haskell.) May 1, 2014 at 22:45
  • @leftaroundabout But if I query GHCi for the type of (foldr (.)) I get (a -> b) -> [b -> b] -> a -> b.
    – Fof
    May 1, 2014 at 22:48

1 Answer 1

5

If you look at the type of (.) as

(b2 -> c2) -> (a2 -> b2) -> (a2 -> c2)

then

b1 ~ (a2 -> b2)
b1 ~ (a2 -> c2)

so (b2 ~ c2)

then you can see the type of (foldr (.)) is

(a2 -> b2) -> [(b2 -> b2)] -> (a2 -> b2)

which is the type GHC derives.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.