blob: 42282e752f891034603e7c783a84e7648bb194d0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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))
|