diff options
| author | Jan Sucan <jan@jansucan.com> | 2023-03-09 20:50:49 +0100 |
|---|---|---|
| committer | Jan Sucan <jan@jansucan.com> | 2023-03-09 20:50:49 +0100 |
| commit | 32af1594520d1ce6f4166a8da5a8635d636968ed (patch) | |
| tree | a9406c612a26069ef8e2b24dda6e6a69c7720cfb | |
| parent | dfb5aa8667e2b4278ee3986d8d88df9bf42ae86d (diff) | |
2_b_3: Add solution
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | ch02/2_b_3.txt | 14 |
2 files changed, 15 insertions, 1 deletions
@@ -50,7 +50,7 @@ more visible in the list the first exercise of a group is in bold italics. | **_2_a_1_** | yes | 25 | 2. Types and functions | | **_2_b_1_** | yes | 39 | | | 2_b_2 | yes | | | -| 2_b_3 | | | | +| 2_b_3 | yes | | | | **_3_a_1_** | | 60 | 3. Defining types, streamlining functions | | 3_a_2 | | | | | **_3_b_1_** | | 69 | | diff --git a/ch02/2_b_3.txt b/ch02/2_b_3.txt new file mode 100644 index 0000000..2b818de --- /dev/null +++ b/ch02/2_b_3.txt @@ -0,0 +1,14 @@ +-- Load your lastButOne function into ghci, and try it out on lists of different +-- lengths. What happens when you pass it a list that's too short? + +ghci> :l 2_b_2.hs +[1 of 1] Compiling Main ( 2_b_2.hs, interpreted ) +Ok, one module loaded. +ghci> lastButOne [1, 2, 3, 4] +3 +ghci> lastButOne [1, 2, 3] +2 +ghci> lastButOne [1, 2] +1 +ghci> lastButOne [1] +*** Exception: Prelude.tail: empty list |
