Created
July 15, 2019 07:32
-
-
Save bitwombat/bfc82b0c00821e80ee823c93bbbe719b to your computer and use it in GitHub Desktop.
Page440 solution to exercise in HPFFP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Page440 where | |
data BinaryTree a = | |
Leaf | |
| Node (BinaryTree a) a (BinaryTree a) | |
deriving (Eq, Ord, Show) | |
mapTree :: (a -> b) | |
-> BinaryTree a | |
-> BinaryTree b | |
mapTree _ Leaf = Leaf | |
mapTree f (Node left a right) = | |
Node (mapTree f left) (f a) (mapTree f right) | |
testTree' :: BinaryTree Integer | |
testTree' = | |
Node (Node Leaf 3 Leaf) | |
1 | |
(Node Leaf 4 Leaf) | |
mapExpected = | |
Node (Node Leaf 4 Leaf) | |
2 | |
(Node Leaf 5 Leaf) | |
-- acceptance test for mapTree | |
mapOkay = | |
if mapTree (+1) testTree' == mapExpected | |
then print "yup okay!" | |
else error "test failed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment