diff options
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | ch03/3_a_2.hs | 25 |
2 files changed, 27 insertions, 2 deletions
@@ -1,5 +1,5 @@ # Real World Haskell solutions - +0;115;0c These are solutions to exercises from me reading the first edition of the [the Real World Haskell book](https://book.realworldhaskell.org/). I hope they will be helpful in your journey to the world of Haskell. @@ -52,7 +52,7 @@ more visible in the list the first exercise of a group is in bold italics. | 2_b_2 | yes | | | | 2_b_3 | yes | | | | **_3_a_1_** | yes | 60 | 3. Defining types, streamlining functions | -| 3_a_2 | | | | +| 3_a_2 | yes | | | | **_3_b_1_** | | 69 | | | 3_b_2 | | | | | 3_b_3 | | | | 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)) |
