From 3c4ac7d6191f6a1dcc9218dfffa17ec7e491acde Mon Sep 17 00:00:00 2001 From: Jan Sucan Date: Sat, 22 Apr 2023 16:27:28 +0200 Subject: 8_a_1: Add solution --- README.md | 2 +- ch08/8_a_1.hs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 ch08/8_a_1.hs diff --git a/README.md b/README.md index 90614f0..0091771 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ of a group is in bold italics. | 5_a_2 | yes, in 5_a_1 | | | | **_6_a_1_** | yes | 162 | 6. Using typeclasses | | 6_a_2 | yes | | | -| **_8_a_1_** | | 205 | 8. Efficient file processing, regular expressions, and file name matching | +| **_8_a_1_** | yes | 205 | 8. Efficient file processing, regular expressions, and file name matching | | 8_a_2 | | | | | **_8_b_1_** | | 210 | | | 8_b_2 | | | | diff --git a/ch08/8_a_1.hs b/ch08/8_a_1.hs new file mode 100644 index 0000000..d918b6d --- /dev/null +++ b/ch08/8_a_1.hs @@ -0,0 +1,23 @@ +-- Use ghci to explore what happens if you pass a malformed pattern, such as [, +-- to globToRegex. Write a small function that calls globToRegex, and pass it a +-- malformed pattern. What happens? + +-- When trying to load the GlobRegex.hs file into ghci, I got an error about +-- that the module was not found. I used Hoogle (https://hoogle.haskell.org/) to +-- search for Text.Regex.Posix module and found it was in regex-posix package. I +-- use stack, so I installed the package by +-- +-- stack install regex-posix + +import GlobRegex + +callGlobToRegex glob = globToRegex glob + +-- ghci> :l 8_a_1.hs +-- [1 of 2] Compiling GlobRegex ( GlobRegex.hs, interpreted ) +-- [2 of 2] Compiling Main ( 8_a_1.hs, interpreted ) +-- Ok, two modules loaded. +-- ghci> callGlobToRegex "[" +-- "^*** Exception: unterminated character class +-- CallStack (from HasCallStack): +-- error, called at ./GlobRegex.hs:27:31 in main:GlobRegex -- cgit v1.2.3