Skip to Content
Effective Haskell
book

Effective Haskell

by Rebecca Skinner
July 2023
Intermediate to advanced
670 pages
17h 13m
English
Pragmatic Bookshelf
Content preview from Effective Haskell

Exercises

Planting Trees

Consider a binary tree with a type:

 data​ ​BinaryTree​ a = ​Leaf​ | ​Branch​ (​BinaryTree​ a) a (​BinaryTree​ a)

Write the definition of the binary tree type, and then add the following functions:

 -- Turn a binary tree of strings into a pretty-printed string
 showStringTree :: ​BinaryTree​ ​String​ -> ​String
 
 -- Add a new integer into a binary tree of integers
 addElementToIntTree :: ​BinaryTree​ ​Int​ -> ​Int​ -> ​BinaryTree​ ​Int
 
 -- Check to see if an int value exists in a binary tree of ints
 doesIntExist :: ​BinaryTree​ ​Int​ -> ​Int​ -> ​Bool

Eval Division by Zero

Write a new version of your eval function named safeEval that will return an error if the user tries to divide by zero. It should have ...

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

Grokking Functional Programming

Grokking Functional Programming

Michal Plachta
Grokking Algorithms

Grokking Algorithms

Aditya Bhargava
The Rust Programming Language, 2nd Edition

The Rust Programming Language, 2nd Edition

Steve Klabnik, Carol Nichols

Publisher Resources

ISBN: 9798888650400Errata Page