Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Your responsibility in this homework is to explore functional programming, pattern matching, and higher-order functions. You will do this in the context of writing several
Your responsibility in this homework is to explore functional programming, pattern matching, and higher-order functions. You will do this in the context of writing several utility functions in Haskell. Write the following Functions in Haskell.
Function frotoByNearness to generate a sorted list of consecutive pairs spanning a list of Integers. Write your function in point-free style by composing your froto function and the sortWith function. Sort such that the pair whose absolute difference is smallest appears first in the list. For example, frotoByNearness [1, 5, -3, 2](,5), (-3,2), (5,-3)1 Function nearestPair to yield from the list of Integers given as a parameter the consecutive pair whose elements are closest. Use composition and implement your function in point-free style. For example. nearestPair [1, 5, -3, 2]? (1,5) Function mapButLast that accepts a transformation function and a list, much like the builtin map, but it generates the new list by applying the function to all elements but the last. For example, mapButLast (+1) [1.5]? [2, 3, 4, 5, 5] Function implode that accepts a separator String and a list of Showable items. It concatenates the items together with intervening separators. For example, implode " , " [1 . . 3] ? " 1 , 2, 3" Use function composition, mapButLast, and partial function application to write this in nearly point-free style. (You should only need to name the first parameter.) Function normspace that accepts a String parameter and returns a String like the param- eter, but with all sequences of multiple spaces character reduced to one space character example, normspace "the.wee-dog--yipped" ? "the.wee, dog.yipped". Use function composition and the group function to write this in point-free style Function frotoByNearness to generate a sorted list of consecutive pairs spanning a list of Integers. Write your function in point-free style by composing your froto function and the sortWith function. Sort such that the pair whose absolute difference is smallest appears first in the list. For example, frotoByNearness [1, 5, -3, 2](,5), (-3,2), (5,-3)1 Function nearestPair to yield from the list of Integers given as a parameter the consecutive pair whose elements are closest. Use composition and implement your function in point-free style. For example. nearestPair [1, 5, -3, 2]? (1,5) Function mapButLast that accepts a transformation function and a list, much like the builtin map, but it generates the new list by applying the function to all elements but the last. For example, mapButLast (+1) [1.5]? [2, 3, 4, 5, 5] Function implode that accepts a separator String and a list of Showable items. It concatenates the items together with intervening separators. For example, implode " , " [1 . . 3] ? " 1 , 2, 3" Use function composition, mapButLast, and partial function application to write this in nearly point-free style. (You should only need to name the first parameter.) Function normspace that accepts a String parameter and returns a String like the param- eter, but with all sequences of multiple spaces character reduced to one space character example, normspace "the.wee-dog--yipped" ? "the.wee, dog.yipped". Use function composition and the group function to write this in point-free styleStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started