Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

9. The Haskell built-in functions fromEnum and toEnum can be used to convert Chars to Ints and vice versa respectively. For example, fromEnum a

image

9. The Haskell built-in functions fromEnum and toEnum can be used to convert Chars to Ints and vice versa respectively. For example, fromEnum a returns 97, fromEnum b' returns 98, etc., all the way to fromEnum 2' which returns 122 (that is, 97 + 25). Similarly, toEnum 97 returns 'a', toEnum 98 returns 'b' etc. a) Write a Haskell function, shift (k, v), using fromEnum and to Enum, that takes a pair consisting of an Int k and a lower-case Char v as arguments, and returns a lower-case Char which is obtained by circularly shifting the input Charv k times to the right using the 26-character English alphabet: abcdefghijklmnopqrstuvwxyz. E.g., *Main> shift (3, 'a') *Main> shift (3, 'y') You may want to use the library function mod, which outputs its first argument modulo its second argument (in other words, the remainder of the first argument divided by the second argument). E.g., *Main> mod 16 3 1 *Main> mod 17 3 2

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

Organic Chemistry A Short Course

Authors: Harold Hart, Christopher M. Hadad, Leslie E. Craine, David J. Hart

13th edition

1111425566, 978-1111425562

More Books

Students also viewed these Programming questions

Question

2. How might culture influence perceptions of fairness?

Answered: 1 week ago