diff options
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)) |
