Using the law map f (map g list) === map (f . g) list We can deduce map sum (map (x:) xss) = map (sum . (x:)) xss = eta-expand to give an argument to work with map (\xs -> sum . (x:) $ xs) xss = Substituting in for...

Well, first do some η-expansion fc :: [a->b] -> (b->a) -> a->b fc xss f = let ope x y = x . f . y in \q -> foldr1 ope xss q fc xss f q = let ope x y = x . f . y in foldr1...

haskell,fold,equational-reasoning

The foldr function is defined as follows: foldr :: (a -> b -> b) -> b -> [a] -> b foldr _ a [] = a foldr f a (x:xs) = f x (foldr f a xs) Now consider the following expression: foldr (\x y -> (x + y) *...

Finally I understood. 1) sep [1, 2, 3, 4, 5] = let (is, ps) = sep [3, 4, 5] in (1:is, 2:ps) 2) sep [3, 4, 5] = let (is, ps) = sep [5] in (3:is, 4:ps) 3) sep [5] = ([], [5]) In 2) sep [3, 4, 5] =...

haskell,partial-application,equational-reasoning

Just keep expanding: pp1 [1, 2, 3, 4] = zip /:/ xnull tail $ [1, 2, 3, 4] -- inline (/:/) f g x = f x (g x) -- f = zip, g = xnull tail, x = [1, 2, 3, 4] -- therefore: = zip [1, 2, 3,...

python,sum,tuples,reduce,equational-reasoning

The actual problem is, with the sum's default start value. Quoting the documentation, Sums start and the items of an iterable from left to right and returns the total. start defaults to 0. The iterable‘s items are normally numbers, and the start value is not allowed to be a string....

This can be seen by induction. Suppose, xs == []. Both expressions are true, since both yield error. Suppose, xs == [y] maximum([y]++map(x+)[y]) == -- by definition of map == maximum([y]++[x+y]) -- by definition of ++ == maximum([y,x+y]) -- by definition of maximum == foldr1 max [y,x+y] -- by definition...