From: Samir Benmendil Date: Tue, 23 Jan 2018 22:27:16 +0000 (+0000) Subject: Show values (except Lists) X-Git-Url: https://git.rmz.io/my-scheme.git/commitdiff_plain/fabc3d8bdaef310b2f18bc53735ad7ee53518822?ds=inline Show values (except Lists) We introduce a `showVal :: LispVal -> String` function, to turn a LispVal into a printable string. This function uses pattern matching to "specialize" on various types. The declaration that matches the specific type is chosen. --- diff --git a/app/Main.hs b/app/Main.hs index fb8294a..1495605 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -94,7 +94,15 @@ parseExpr = parseString readExpr :: String -> String readExpr input = case parse parseExpr "lisp" input of Left err -> "No match: " ++ show err - Right val -> "Found value: " ++ show val + Right val -> "Found value: " ++ showVal val + +showVal :: LispVal -> String +showVal (Atom atom) = atom +showVal (Number n) = show n +showVal (String str) = "\"" ++ str ++ "\"" +showVal (Character c) = "'" ++ [c] ++ "'" +showVal (Bool True) = "#t" +showVal (Bool False) = "#f" main :: IO () main = do