diff options
| author | Jan Sucan <jan@jansucan.com> | 2023-03-10 16:48:53 +0100 |
|---|---|---|
| committer | Jan Sucan <jan@jansucan.com> | 2023-03-10 16:48:53 +0100 |
| commit | dc15d5bd73107b5578b8f26c70bba1339041be0a (patch) | |
| tree | 9f48d07105662ed139f20bb1fadf0005c02cc4f3 /ch03/3_a_2.hs | |
| parent | 5cd664fe805f5c026c908ac0202edc30f28106b7 (diff) | |
3_a_2: Add solution
Diffstat (limited to 'ch03/3_a_2.hs')
| -rw-r--r-- | ch03/3_a_2.hs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/ch03/3_a_2.hs b/ch03/3_a_2.hs new file mode 100644 index 0000000..42282e7 --- /dev/null +++ b/ch03/3_a_2.hs @@ -0,0 +1,25 @@ +-- Define a tree type that has only one constructor, like our Java +-- example. Instead of the Empty constructor, use the Maybe type to refer to a +-- node's children. + +-- The assignment doesn't explicitly specify whether it should be possible to +-- create an empty tree at the root level, so this tree type doesn't support +-- that. + +data Tree a = Node a (Maybe (Tree a)) (Maybe (Tree a)) + deriving (Show) + + +-- parent +-- /\ +-- / \ +-- left child right child +-- / +-- / +-- left child + +simpleTree = Node "parent" (Just (Node "left child" Nothing + Nothing)) + (Just (Node "right child" (Just (Node "left child" Nothing + Nothing)) + Nothing)) |
