1

Haskell beginner here having problem deriving the type of (.).(.) --

Prelude> :t ((.).(.))
((.).(.)) :: (b -> c) -> (a -> a1 -> b) -> a -> a1 -> c

This is how I think: suppose (.).(.) takes two arguments A and B, then

(.).(.) A B = (.).(A.B)

and suppose the above takes another argument C --

(.).(A.B) C = (.)((A.B) C)

adding argument D to the above --

(.)((A.B) C) D = ((A.B) C).D

where D, A, B, A.B, and ((A.B) C) are(return) functions, and --

D :: a -> b
(A.B) C :: b -> c
A.B :: d -> b -> c
A :: e -> b -> c
B :: d -> e
C :: d

so (.).(.) :: A -> B -> C -> D becomes --

(.).(.) :: (e -> b -> c) -> (d -> e) -> d -> a -> b

which is light years away from the correct type signature.

What's the proper derivation and what's wrong in my steps?

Jerry
  • 2,497
  • 4
  • 22
  • 31
  • Sibi you are right, the question itself is not an exact duplicate, but J. Abrahamson's answer pretty much covers my question (even though I'm not following his step of "((.) (.) (.) :: (b'' -> c'') -> (a' -> b') -> (a' -> c'))", particularly at the second argument (a' -> b') – Jerry Jun 04 '14 at 06:29
  • @Jerry: J. Abrahamson is still an active member of the community, if you have some comments/questions regarding his answer, you should comment his post. – Zeta Jun 04 '14 at 06:39

1 Answers1

1

It seems my error comes from applying the three dots in the wrong order.

J. Abrahamson's answer is great, but I'm not exactly following his step --

((.) (.) (.) :: (b'' -> c'') -> (a' -> b') -> (a' -> c'))
                ^^^^^^^^^^^^    ^^^^^^^^^^ 

due to the way his "mixes" up the first and second arguments from the second and the third dot type.

I think I've got the answer following my original track of thoughts --

(.).(.) A = (.)((.) A)) ==> add arg B ==> (.)((.) A)) B = ((.) A).B ==>
add arg C ==> ((.) A).B C = ((.) A)(B C) ==> add arg D ==> ((.) A)(B C) D

where A, ((.) A), (B C) are functions --

let A :: b -> c
then ((.) A) :: (a -> b) -> a -> c
so B C :: a -> b
B :: a1 -> a -> b
C :: a1
D :: a

and (.).(.) A B C D expands to --

(.).(.) :: (b -> c) -> (a1 -> a -> b) -> a1 -> a -> c
Community
  • 1
  • 1
Jerry
  • 2,497
  • 4
  • 22
  • 31