CECS 424 Assignment 11

$25.00

Download Details:

  • Name: Assignment-11-4llldy.zip
  • Type: zip
  • Size: 147.38 KB

Category: Tags: ,

Description

Rate this product

1. (5 points) The myfoldr and mylengthr are defined in Haskell as follows:
myfoldr :: (a -> b -> b) -> b -> [a] -> b
myfoldr f acc [] = acc
myfoldr f acc (x:xs) = f x (myfoldr f acc xs)
mylengthr :: [a] -> Int
mylengthr = myfoldr (\ n -> 1 + n) 0
Show the evaluation steps of mylengthr [1,2,3] => … => 3.

2. The myfoldl is defined in Haskell as follows:
myfoldl :: (a -> b -> a) -> a -> [b] -> a
myfoldl f acc [] = acc
myfoldl f acc (x:xs) = myfoldl f (f acc x) xs
(a) (5 points) Write a function called mylengthl using myfoldl. The mylengthl
should output the length of a given list.
(b) (5 points) Show the evaluation steps of mylengthl [1,2,3] => … => 3.

3. The reverse of a list can be computed by using the folding left function.
(a) (5 points) Write a function called myreverse using myfoldl. The myreverse
should output the reverse of a given list.
(b) (5 points) Show the evaluation steps of myreverse [1,2,3] => … => [3,2,1].