Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in haskell i - - The Haskell Prelude has a lot of useful built-in functions related - to numbers and lists. In Part 2 of

in haskell image text in transcribed iimage text in transcribedimage text in transcribed

- - The Haskell Prelude has a lot of useful built-in functions related - to numbers and lists. In Part 2 of this lab, you will catalog many . - of these functions. . Below is the definition of a new color type (also called an - "enumeration type"). You will be using this, when you can, in - experimenting with the functions and operators below. data Color = Red Orange | Yellow | Green | Blue | Violet deriving (Show, Eq, ord, Enum) . For each of the Prelude functions listed below, give its type, . - describe briefly in your own words what the function does, answer - any questions specified, and give several examples of its use, . - including examples involving the color type, if appropriate (note - that Color, by the deriving clause, is an Eq, Ord, and Enum type). - - Include as many examples as necessary to illustration all of the - features of the function. Put your answers inside {} comments. - I've done the first one for you (note that " : " is my ghci prompt). - succ, pred {= succ :: Enum a a > a pred :: Enum aa>a For any Enum type, succ gives the next element of the type after the given one, and pred gives the previous. Asking for the succ of the last element of the type, or the pred of the first element of the type results in an error. :succ5 6 :succd ' 'e' : succ False True : succ True Exception: Prelude. Enum. Bool. succ: bad argument : succ Orange Yellow : succ Violet Exception: succ\{Color\}: tried to take 'succ' of last tag in enumeratic CallStack (from HascallStack): error, called at lab1.hs:18:31 in main:Main : pred 6 5 : pred ' e ' d ' : pred True False : pred False *** Exception: Prelude. Enum. Bool.pred: bad argument : pred Orange Red : pred Red *** Exception: pred\{Color\}: tried to take 'pred' of first tag in enumeration Callstack (from HasCallStack): error, called at lab1.hs:18:31 in main:Main 3 - - toEnum, fromEnum, enumFrom, enumFromThen, enumFromTo, enumFromThenTo - As one of your examples, try (toEnum 3) : Color ==,/= - quot, div (Q: what is the difference? Hint: negative numbers) - rem, mod (Q: what is the difference? Hint: negative numbers) - quotRem, divMod &&, - compare . - max, min . - concat - const - cycle - drop, take - e elem - even - - fst - gcd - - head .. id - - init - last - lcm - - length - - null - odd - repeat - replicate - - reverse - - snd - splitAt - - zip - The rest of these are higher-order, i.e., they take functions as - arguments. This means that you'll need to "construct" functions to - provide as arguments if you want to test them. - all, any - break - dropwhile, takewhile - filter - iterate - map - span

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions

Question

1. define character development and good sporting behavior,

Answered: 1 week ago