b) -> [a] -> [b]map' f xs = foldr ((:) . f) [] xs1The evaluation of map' succ [1,2,3] results in the list [2,3,4]. There are several duality theo-rems that can be stated for fold functions. Prove...


The fold functions compute a value over a list (or some other type that is foldable) by applying an<br>operator to the list elements and a neutral element. The foldl function assumes that the operator<br>is left associative, the foldr function assumes that the operatore is right associative. For example,<br>the function application<br>foldl (+) 0 [3,5,2,1]<br>1<br>results in the computation of (((0+3)+5)+2)+1) and the function application<br>foldr (+) 0 [3,5,2,1]<br>1<br>results in the computation of (3+(5+(2+(1+0)). The value computed by the fold functions may be<br>more complex than a simple scalar. It is very well possible to construct a new list as part of the<br>fold. For example:<br>map' :: (a -> b) -> [a] -> [b]<br>map' f xs = foldr ((:) . f) [] xs<br>1<br>The evaluation of map' succ [1,2,3] results in the list [2,3,4]. There are several duality theo-<br>rems that can be stated for fold functions. Prove the following three duality theorems:<br>a) Let op be an associative operation with e as the neutral element:<br>op is associative: (x op y) op z = x op (y op z)<br>e is neutral element: e op x = x and x op e = x<br>Then the following holds for finite lists xs:<br>foldr op e xs = foldl op e XS<br>b) Let op1 and op2 be two operations for which<br>x `op1 (y `op2 z) = (x `op1 y)`op2` z<br>x `op1 e<br>= e `op2` x<br>holds. Then the following holds for finite lists xs:<br>foldr op1 e xs = foldl op2 e xs<br>c) Let op be an associative operation and xs a finite list. Then<br>foldr op a xs = foldl op' a (reverse xs)<br>holds with<br>х ор' у 3 у ор х<br>

Extracted text: The fold functions compute a value over a list (or some other type that is foldable) by applying an operator to the list elements and a neutral element. The foldl function assumes that the operator is left associative, the foldr function assumes that the operatore is right associative. For example, the function application foldl (+) 0 [3,5,2,1] 1 results in the computation of (((0+3)+5)+2)+1) and the function application foldr (+) 0 [3,5,2,1] 1 results in the computation of (3+(5+(2+(1+0)). The value computed by the fold functions may be more complex than a simple scalar. It is very well possible to construct a new list as part of the fold. For example: map' :: (a -> b) -> [a] -> [b] map' f xs = foldr ((:) . f) [] xs 1 The evaluation of map' succ [1,2,3] results in the list [2,3,4]. There are several duality theo- rems that can be stated for fold functions. Prove the following three duality theorems: a) Let op be an associative operation with e as the neutral element: op is associative: (x op y) op z = x op (y op z) e is neutral element: e op x = x and x op e = x Then the following holds for finite lists xs: foldr op e xs = foldl op e XS b) Let op1 and op2 be two operations for which x `op1 (y `op2 z) = (x `op1 y)`op2` z x `op1 e = e `op2` x holds. Then the following holds for finite lists xs: foldr op1 e xs = foldl op2 e xs c) Let op be an associative operation and xs a finite list. Then foldr op a xs = foldl op' a (reverse xs) holds with х ор' у 3 у ор х
Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here