Calculating type of polymorphism haskell

Viewed 84

I need to calculate types of following expressions:

  • curry fst
  • foldr const
  • (foldr const) . (curry fst)

First I have:

curry :: ((a, b) -> c) -> a -> b -> c
fst :: (d, e) -> d 

{}                      |   (a,b)-> c = (d,e) -> d 
{}                      |   (a,b) = (d,e) , c = d
c -> d                  |   (a,b) = (d,e)
c -> d , a ->d          |   b = e
c -> d , a ->d, b -> e  |   {}

then replace the result in a -> b -> c and you get d -> e -> d

Now similar to this I do:

foldr :: (f -> g -> g) -> g -> [f] -> g
const :: h -> i -> h



{}                      |    (f -> g -> g) =  h -> i -> h 
{}                      |    f = h , g = i, g = h
f -> h                  |    g = i, g = h
f -> h, g -> i          |    i = h
f -> h, g -> i  i->h    |    {}

then replace the result in g -> [f] -> g and you get i -> [h] -> i

Next, i have to do (foldr const) . (curry fst) but i am not sure if these results are correct. I tried anyway but got stuck. So:

(foldr const) :: i -> [h] -> i and (curry fst) :: d -> e -> d
(.) :: (j -> k) -> (l -> j) -> l -> k

then i start with:

d = (j -> k) -> (l -> j) -> l -> k, e = d -> e -> d

e = (j -> k) -> (l -> j) -> l -> k -> e -> (j -> k) -> (l -> j) -> l -> k

but it feels wrong and i cannot continue... Are my first two results correct? If they are, how should i solve the last one?

1 Answers
Related