diff options
| author | Jan Sucan <jan@jansucan.com> | 2023-03-10 16:12:15 +0100 |
|---|---|---|
| committer | Jan Sucan <jan@jansucan.com> | 2023-03-10 16:12:15 +0100 |
| commit | 5cd664fe805f5c026c908ac0202edc30f28106b7 (patch) | |
| tree | d2365be99e1e58b7d8e50f33dc4296329fb2bed1 | |
| parent | 54afee05a42a7814a6261822b855b14fcdcaa41e (diff) | |
3_a_1: Add solution
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | ch03/3_a_1.hs | 14 |
2 files changed, 15 insertions, 1 deletions
@@ -51,7 +51,7 @@ more visible in the list the first exercise of a group is in bold italics. | **_2_b_1_** | yes | 39 | | | 2_b_2 | yes | | | | 2_b_3 | yes | | | -| **_3_a_1_** | | 60 | 3. Defining types, streamlining functions | +| **_3_a_1_** | yes | 60 | 3. Defining types, streamlining functions | | 3_a_2 | | | | | **_3_b_1_** | | 69 | | | 3_b_2 | | | | diff --git a/ch03/3_a_1.hs b/ch03/3_a_1.hs new file mode 100644 index 0000000..6e2b634 --- /dev/null +++ b/ch03/3_a_1.hs @@ -0,0 +1,14 @@ +-- Write the converse of fromList for the List type: a function that takes a +-- List a and generates a [a]. + +{-- From examples/examples/ch03/ListADT.hs --} +data List a = Cons a (List a) + | Nil + deriving (Show) +{-- End of code from examples --} + +toList (Cons x xs) = x:(toList xs) +toList Nil = [] + +-- ghci> toList (Cons 1 (Cons 2 (Cons 3 Nil))) +-- [1,2,3] |
