aboutsummaryrefslogtreecommitdiff
path: root/src/Error.hs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-10-13 13:37:08 +0100
committerAkshay <[email protected]>2020-10-13 13:37:08 +0100
commit8641ce3e1a730c8195e5a74fabef8814f43b05f8 (patch)
treecdacd671ba7445c4823ffb8bbccb20de6e56f655 /src/Error.hs
parent4842ab6362077a62893ac79b752c7da5578292b9 (diff)
refactor Error into submodules
Diffstat (limited to 'src/Error.hs')
-rw-r--r--src/Error.hs31
1 files changed, 0 insertions, 31 deletions
diff --git a/src/Error.hs b/src/Error.hs
deleted file mode 100644
index bfc8d14..0000000
--- a/src/Error.hs
+++ /dev/null
@@ -1,31 +0,0 @@
1module Error (
2 LispError (..)
3 , LispResult (..)
4 , unwrap
5 ) where
6
7import Control.Monad.Except
8import Parser
9import Text.ParserCombinators.Parsec
10
11data LispError = Parse ParseError
12 | BadForm String Expr
13 | ArgCount Int [Expr]
14 | UnknownFunction String
15 | TypeMismatch String Expr
16
17unwordsList :: [Expr] -> String
18unwordsList = unwords . map show
19
20instance Show LispError where
21 show (Parse e) = "Parser Error: " ++ show e
22 show (BadForm s expr) = "Bad Form: " ++ s ++ ": " ++ show expr
23 show (ArgCount n es) = "Invalid arity, expected " ++ show n ++ ", got value(s): " ++ unwordsList es
24 show (UnknownFunction fn) = "Cannot apply function: " ++ fn
25 show (TypeMismatch msg got) = "Type mismatch, expected " ++ msg ++ ", got: " ++ show got
26
27type LispResult = Either LispError
28
29unwrap :: LispResult t -> t
30unwrap (Right v) = v
31unwrap (Left _) = undefined -- should panic