
module Comp where

--------------------
-- Jerzy pointed this out (I only noticed the case n = 2)


--------------------
-- composition of 1-arg fns (yes, a useless example)

lentail = length . tail


--------------------
-- composition of 1-arg with 2-arg

(.<) = (.) . (.)


stutter = concat .< replicate

		-- > stutter 3 "foo"
		-- "foofoofoo"
		
		-- versus:
		-- stutter n xs = concat (replicate n xs)

stammer = concat .< (map . replicate)

		-- > stammer 3 "foo"
		-- "fffoooooo"
		
		-- versus:
		-- stammer n xs = concat (map (replicate n) xs)


--------------------
-- composition of 1-arg with 3-arg

(.<<) = (.) . (.) . (.)

sqfold = (^2) .<< foldr

		-- > sqfold (+) 0 [1..3]
		-- 36
		-- > sqfold (*) 1 [1..3]
		-- 36
		
		-- > sqfold (+) 1 [1..4]
		-- 121
		-- > sqfold (*) 1 [1..4]
		-- 576


--------------------
-- So we have:

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


-- But we can't generalize to n this way
-- ("unification would give infinite type")
-- and we couldn't write it infix anyway: no `dot n`

-- dot n = foldr1 (.) (replicate n (.))



