aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--ch03/3_b_1.hs25
2 files changed, 26 insertions, 1 deletions
diff --git a/README.md b/README.md
index 22b09be..113edbb 100644
--- a/README.md
+++ b/README.md
@@ -53,7 +53,7 @@ more visible in the list the first exercise of a group is in bold italics.
| 2_b_3 | yes | | |
| **_3_a_1_** | yes | 60 | 3. Defining types, streamlining functions |
| 3_a_2 | yes | | |
-| **_3_b_1_** | | 69 | |
+| **_3_b_1_** | yes | 69 | |
| 3_b_2 | | | |
| 3_b_3 | | | |
| 3_b_4 | | | |
diff --git a/ch03/3_b_1.hs b/ch03/3_b_1.hs
new file mode 100644
index 0000000..4db9c0c
--- /dev/null
+++ b/ch03/3_b_1.hs
@@ -0,0 +1,25 @@
+-- Write a function that computes the number of elements in a list. To test it,
+-- ensure that it gives the same answers as the standard length function.
+
+myLength (x:xs) = 1 + myLength xs
+myLength [] = 0
+
+-- ghci> :l 3_b_1.hs
+-- [1 of 1] Compiling Main ( 3_b_1.hs, interpreted )
+-- Ok, one module loaded.
+-- ghci> myLength []
+-- 0
+-- ghci> myLength [1]
+-- 1
+-- ghci> myLength [1, 2]
+-- 2
+-- ghci> myLength [1, 2, 3]
+-- 3
+-- ghci> length []
+-- 0
+-- ghci> length [1]
+-- 1
+-- ghci> length [1, 2]
+-- 2
+-- ghci> length [1, 2, 3]
+-- 3