Skip to Content
Get Programming with Haskell
book

Get Programming with Haskell

by Will Kurt
March 2018
Beginner
616 pages
16h 53m
English
Manning Publications
Content preview from Get Programming with Haskell

Appendix. Answers to end-of-lesson exercises

The beautiful thing about code is that there are no wrong answers as long as you get the right results. The answers to the exercises shown here should be viewed as simply one possible solution to the problem. Especially in Haskell, there are many paths to the correct solution; if you have an alternative answer that gives the correct results, that’s the correct solution.

Unit 1

Lesson 2

Q2.1

inc x = x + 1
double x = x*2
square x = x^2

Q2.2

ex3 n = if n 'mod' 2 == 0
        then n - 2
        else 3*n+1

Q2.3

ifEven n = if even n
           then n - 2
           else 3 * n + 1

Lesson 3

Q3.1

simple = (\x -> x)
makeChange = (\owed given ->
               if given - owed > 0
               then given - owed
               else 0)

Q3.2

inc = (\x -> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Get Programming with Go

Get Programming with Go

Nathan Youngman, Roger Peppe
Effective Haskell

Effective Haskell

Rebecca Skinner

Publisher Resources

ISBN: 9781617293764Publisher SupportOtherPublisher WebsiteSupplemental ContentErrata PagePurchase Link