How to calculate type of (.)(.) in Haskell? I know that it should be
(.)(.) :: (a -> b -> c) -> a -> (a1 -> b) -> a1 -> c
But how to calculate it without computer?
(.)    :: (b        -> c                     ) -> ((a -> b)        -> (a -> c))
   (.) :: ((e -> f) -> ((d -> e) -> (d -> f)))
(.)(.) ::                                         ((a -> (e -> f)) -> (a -> ((d -> e) -> (d -> f))))
(.)(.) :: (a -> (e -> f)) -> (a -> ((d -> e) -> (d -> f)))
(.)(.) :: (a -> e -> f) -> a -> ((d -> e) -> (d -> f))
(.)(.) :: (a -> e -> f) -> a -> (d -> e) -> (d -> f)
(.)(.) :: (a -> e -> f) -> a -> (d -> e) -> d -> f
                        (.) has type (b -> c) -> ((a -> b) -> a -> c) so the first argument should have type b -> c.
Now if we use it again we have to substitute b with b' -> c' and c with (a' -> b') -> a' -> c') (the second (.) should have type (b' -> c') -> ((a' -> b') -> a' -> c')) and we get
(a -> b' -> c') -> a -> (a' -> b') -> a' -> c'
which is (after renaming) the same as above.
Note that I used a -> b -> c = a -> (b -> c) here
yeah I know - you want it by hand - but GHCi is such a valuable tool that you really should use it to confirm your manual labor.
Here from a terminal:
$ ghci
GHCi, version 7.10.1: http://www.haskell.org/ghc/  :? for help
Prelude> :t (.)(.)
(.)(.) :: (a -> b -> c) -> a -> (a1 -> b) -> a1 -> c
Prelude> 
as you can see the type is (a -> b -> c) -> a -> (a1 -> b) -> a1 -> c
btw: :t is short for :type and you can see all commands with :help from inside a GHCi session.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With