diff options
Diffstat (limited to 'lore/Language/Bs/Primitives.hs')
-rw-r--r-- | lore/Language/Bs/Primitives.hs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lore/Language/Bs/Primitives.hs b/lore/Language/Bs/Primitives.hs index 2c90164..6042b82 100644 --- a/lore/Language/Bs/Primitives.hs +++ b/lore/Language/Bs/Primitives.hs @@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE NoImplicitPrelude #-} -- | bs primitives -- -- I would like to reduce the number of primitives in the language to some @@ -13,6 +14,7 @@ import Data.Text as T import Data.Text.IO as TIO import Language.Bs.Expr import Network.HTTP +import Protolude import System.Directory import System.IO @@ -51,7 +53,7 @@ primEnv = [ , ("file?" , mkF $ unop fileExists) , ("slurp" , mkF $ unop slurp) , ("wslurp" , mkF $ unop wSlurp) - , ("put" , mkF $ binop put) + , ("put" , mkF $ binop put_) ] unop :: Unary -> [Expr] -> Eval Expr @@ -91,10 +93,10 @@ readTextFile fileName handle = do then (TIO.hGetContents handle) >>= (return . Tape) else throw $ ReadFileError $ T.concat [" file does not exist: ", fileName] -put :: Expr -> Expr -> Eval Expr -put (Tape file) (Tape msg) = liftIO $ wFilePut file msg -put (Tape _) val = throw $ TypeMismatch "put expects string in the second argument (try using show), instead got: " val -put val _ = throw $ TypeMismatch "put expects string, instead got: " val +put_ :: Expr -> Expr -> Eval Expr +put_ (Tape file) (Tape msg) = liftIO $ wFilePut file msg +put_ (Tape _) val = throw $ TypeMismatch "put expects string in the second argument (try using show), instead got: " val +put_ val _ = throw $ TypeMismatch "put expects string, instead got: " val wFilePut :: T.Text -> T.Text -> IO Expr wFilePut fileName msg = withFile (T.unpack fileName) WriteMode go |