From: Samir Benmendil Date: Sat, 13 Jan 2018 23:05:55 +0000 (+0000) Subject: readExpr function to check whether the input matches symbol X-Git-Url: https://git.rmz.io/my-scheme.git/commitdiff_plain/b95d19b43830747d76eab4c01805ef531e897795?ds=sidebyside readExpr function to check whether the input matches symbol `readExpr :: String -> String` defines `readExpr` to be a function (`->`) from String to a String. `readExpr input = ...` will assign anything on the rhs to the `readExpr` function where `input` is mapped to the first parameter of that function. `case ... of` is a *filter*. `parse a b c` is a function from Parsec where `a` is the parser it should use, `b` is the name of the input which is used for error messages and `c` is the String to parse. `parse` returns an `Either` type whose `Left` constructor indicates an error. If we get a `Right` value, we bind it to `val`, ignore it and return the String "Found Value". --- diff --git a/app/Main.hs b/app/Main.hs index 015db3a..a94dc2c 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -5,7 +5,12 @@ import System.Environment symbol :: Parser Char symbol = oneOf "!#$%&|*+-/:<=>?@^_~" +readExpr :: String -> String +readExpr input = case parse symbol "lisp" input of + Left err -> "No match: " ++ show err + Right val -> "Found value" + main :: IO () main = do args <- getLine - putStrLn (args) + putStrLn (readExpr args)