From 4ecc513e5917057f50150e2cb0a1d63d6010f0d7 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Wed, 27 Mar 2019 22:58:53 -0700 Subject: bs: add protolude and organize imports --- lore/Language/Bs/Primitives.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lore/Language/Bs/Primitives.hs') 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 -- cgit v1.2.3