From d5b3fdf33aabe50ec5d4f07ecef2954ce463a947 Mon Sep 17 00:00:00 2001 From: Yuri Tatishchev Date: Mon, 23 Feb 2026 11:22:37 -0800 Subject: [PATCH] lab06: init --- lab06/functors.lhs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lab06/functors.lhs diff --git a/lab06/functors.lhs b/lab06/functors.lhs new file mode 100644 index 0000000..58cc4d8 --- /dev/null +++ b/lab06/functors.lhs @@ -0,0 +1,21 @@ +> data Tree v = +> Empty +> | Node v (Tree v) (Tree v) +> deriving (Show) + +The findT method shows how we may search through the tree to find a value. + +> findT :: Ord v => v -> Tree v -> Maybe v +> findT _ Empty = Nothing +> findT v (Node val left right) = +> if val == v then +> Just val +> else if v < val then +> findT v left +> else +> findT v right + +Your job is to add support for fmap to this tree, so that the call to fmap below works: + +> main = print $ fmap (+1) (Node 3 (Node 1 Empty Empty) (Node 7 (Node 4 Empty Empty) Empty)) +