diff options
| -rw-r--r-- | src/Builtins.hs | 19 | ||||
| -rw-r--r-- | src/Types.hs | 3 |
2 files changed, 17 insertions, 5 deletions
diff --git a/src/Builtins.hs b/src/Builtins.hs index dc6b44c..1ac532a 100644 --- a/src/Builtins.hs +++ b/src/Builtins.hs @@ -16,14 +16,25 @@ builtinEnv = M.fromList [ ("prepend", builtinPrepend) ] +-- maybe make a builtinBinaryFunction? +-- builtinAdd2 = builtinBinaryFunction (ASTInteger a) (ASTInteger b) (\a b -> a + b) builtinAdd2 :: AST builtinAdd2 = - let outer _ ast1 = do - (ASTInteger a) <- assertIsASTInteger ast1 - let inner _ ast2 = do - (ASTInteger b) <- assertIsASTInteger ast2 + let outer :: LFunction + outer _ (ASTInteger a) = do + let inner :: LFunction + inner _ (ASTInteger b) = return $ ASTInteger $ a + b + inner _ other = throwError $ LException $ "invalid argument to integer add: " ++ show other + return $ ASTFunction $ inner + outer _ (ASTDouble a) = do + let inner :: LFunction + inner _ (ASTDouble b) = + return $ ASTDouble $ a + b + inner _ other = throwError $ LException $ "invalid argument to double add: " ++ show other return $ ASTFunction $ inner + outer _ other = throwError $ LException $ "non-numeric argument to add: " ++ show other + in ASTFunction outer builtinSubtract2 :: AST diff --git a/src/Types.hs b/src/Types.hs index 08736cc..21a1ceb 100644 --- a/src/Types.hs +++ b/src/Types.hs @@ -5,6 +5,7 @@ import Control.Monad.Except import Control.Monad.Reader import qualified Data.Map as M import qualified Data.List as L +import qualified Data.Char as C import Utils newtype LException = LException String @@ -36,7 +37,7 @@ instance (Show AST) where show (ASTInteger n) = show n show (ASTDouble n) = show n show (ASTSymbol s) = s - show (ASTBoolean b) = show b + show (ASTBoolean b) = show b $> map C.toLower show (ASTString s) = show s show (ASTVector v) = "[" ++ L.intercalate " " (map show v) ++ "]" show (ASTFunctionCall v) = "(" ++ L.intercalate " " (map show v) ++ ")" |
