Question: write Haskell functions group using foldr : 6. The foldr for lists (as above) is defined as: foldr f g [] = g foldr f

write Haskell functions "group" using "foldr" :

write Haskell functions "group" using "foldr" : 6. The foldr for lists

6. The foldr for lists (as above) is defined as: foldr f g [] = g foldr f g (x:xs) = f x (foldr f g xs) Using foldr write the function group:: (a->a->Bool)->[a]->[[a]] which, given a predicate p::a->a->Bool and a list, breaks the list into a series of (longest possible) sublists in which any two consecutive elements satisfy the predicate (in particular grouping the empty list will give the list containing the empt list). For example, suppose that the predicate nbr determines whether two integers differ by at most one, then group nbr [] = [] group nbr [2,1,3,4,5,5,4,7,4,3,3] [[2,1], [3,4,5,5,4],[7], [4,3,3]] 6. The foldr for lists (as above) is defined as: foldr f g [] = g foldr f g (x:xs) = f x (foldr f g xs) Using foldr write the function group:: (a->a->Bool)->[a]->[[a]] which, given a predicate p::a->a->Bool and a list, breaks the list into a series of (longest possible) sublists in which any two consecutive elements satisfy the predicate (in particular grouping the empty list will give the list containing the empt list). For example, suppose that the predicate nbr determines whether two integers differ by at most one, then group nbr [] = [] group nbr [2,1,3,4,5,5,4,7,4,3,3] [[2,1], [3,4,5,5,4],[7], [4,3,3]]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!