# rebcabin/CompositionsOfCompositions.txt Last active Dec 14, 2019
 Sorry, even though I know how to combine compositions properly your example is still too confusing and I couldn't get through it. If you don't mind, here is how I see it: Let's go step by step, here is what we need to find: ``````(.)1 . (.)2 :: ??? `````` Because of currying `(.)2` is actually a function of one argument. ``````(.)2 :: (a -> b) -> ((c -> a) -> (c -> b)) `````` Just to keep things terse. ``````ca ~ c -> a cb ~ c -> b (.)2 :: (a -> b) -> (ca -> cb) `````` So it actually can be combined (with our normal two-argument `(.)`) Here is its type: ``````(.) :: (2 -> 3) -> (1 -> 2) -> (1 -> 3) `````` Numbers are here to distinguish between what we know (letters) and what we still need to find (numbers) ``````(.)1 . (.)2 :: 1 -> 3 `````` The second argument `(1 -> 2)` is fully defined by our `(.)2` We can replace it. ``````(.) :: ((ca -> cb) -> 3)) -> ((a -> b) -> (ca -> cb)) -> ((a -> b) -> 3) (.)1 . (.)2 :: (a -> b) -> 3 `````` So the only type we don't know is 3. To find it we need our first argument `(.)1`: ``````(.)1 :: (b -> c) -> (o -> b) -> (o -> c) `````` And we also now: ``````(.)1 :: (ca -> cb) -> 3 `````` Can be substituted again: ``````(.)1 :: (ca -> cb) -> (o -> ca) -> (o -> cb) `````` We still don't know `o` but we can define `3` in terms of it: ``````3 ~ (o -> ca) -> (o -> cb) `````` Here is our final version. ``````(.)1 . (.)2 :: (a -> b) -> (o -> ca) -> (o -> cb) (.)1 . (.)2 :: (a -> b) -> (o -> c -> a) -> (o -> c -> b) `````` We can check it in GHCi: ``````let a = (.) :: (a -> b) -> (c -> a) -> (c -> b) let b = (.) :: (b -> c) -> (o -> b) -> (o -> c) :t b . a b . a :: (a -> b) -> (o -> c -> a) -> o -> c -> b `````` And we can extend it further: ``````:t (.) . (b . a) (.) . (b . a) :: (a1 -> b) -> (a2 -> o -> c -> a1) -> a2 -> o -> c -> b :t (b . a) . (.) (b . a) . (.) :: (b -> c1) -> (o -> c2 -> a -> b) -> o -> c2 -> a -> c1 `````` And further: ``````:t (.).(.).(.).(.) (.).(.).(.).(.) :: (b -> c) -> (a1 -> a2 -> a3 -> a4 -> b) -> a1 -> a2 -> a3 -> a4 -> c `````` Ad infinitum.