diff options
author | Ben Sima <ben@bsima.me> | 2020-04-15 10:06:24 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-04-15 10:07:02 -0700 |
commit | afa9d701538b9e56622a0bfdf8e04aa358c9cd82 (patch) | |
tree | dee95c3955b3fe3d11e80d89823660d28eee0587 /Biz/Language/Bs/Expr.hs | |
parent | f4b8c0df041b063c0b47d2ec6c818a9c202fd833 (diff) |
Reformatting
Now I'm using ormolu instead of brittany for Haskell formatting
now. Figured I should just make all of these big changes at once.
Diffstat (limited to 'Biz/Language/Bs/Expr.hs')
-rw-r--r-- | Biz/Language/Bs/Expr.hs | 157 |
1 files changed, 71 insertions, 86 deletions
diff --git a/Biz/Language/Bs/Expr.hs b/Biz/Language/Bs/Expr.hs index a39c7b6..2452622 100644 --- a/Biz/Language/Bs/Expr.hs +++ b/Biz/Language/Bs/Expr.hs @@ -1,7 +1,8 @@ -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE NoImplicitPrelude #-} + module Language.Bs.Expr where import Data.String (String) @@ -13,17 +14,18 @@ import qualified Text.PrettyPrint.Leijen.Text as PP import Text.PrettyPrint.Leijen.Text hiding ((<$>)) type Ctx = Map Text Expr -data Env = Env { env :: Ctx, fenv :: Ctx } - deriving (Eq) -newtype Eval a = Eval { unEval :: ReaderT Env IO a } - deriving (Monad, Functor, Applicative, MonadReader Env, MonadIO) +data Env = Env {env :: Ctx, fenv :: Ctx} + deriving (Eq) + +newtype Eval a = Eval {unEval :: ReaderT Env IO a} + deriving (Monad, Functor, Applicative, MonadReader Env, MonadIO) -data IFunc = IFunc { fn :: [Expr] -> Eval Expr } - deriving (Typeable) +data IFunc = IFunc {fn :: [Expr] -> Eval Expr} + deriving (Typeable) instance Eq IFunc where - (==) _ _ = False + (==) _ _ = False data Expr = Atom Text @@ -37,7 +39,7 @@ data Expr deriving (Typeable, Eq) instance Show Expr where - show = T.unpack . ppexpr + show = T.unpack . ppexpr data LispErrorType = NumArgs Integer [Expr] @@ -55,12 +57,13 @@ data LispErrorType data LispError = LispError Expr LispErrorType instance Show LispErrorType where - show = T.unpack . ppexpr + show = T.unpack . ppexpr instance Show LispError where - show = T.unpack . ppexpr + show = T.unpack . ppexpr instance Exception LispErrorType + instance Exception LispError ppexpr :: Pretty a => a -> Text @@ -70,85 +73,67 @@ ppexpr x = PP.displayTStrict (PP.renderPretty 1.0 70 (pretty x)) --prettyList = encloseSep lparen rparen PP.space instance Pretty Expr where - pretty v = - case v of - Atom a -> - textStrict a - - List ls -> - prettyList $ fmap pretty ls - - Numb n -> - integer n - - Tape t -> - textStrict "\"" <> textStrict t <> textStrict "\"" - - IFun _ -> - textStrict "<internal function>" - - Func _ _ -> - textStrict "<lambda function>" - - Bool True -> - textStrict "#t" - - Bool False -> - textStrict "#f" - - Nil -> - textStrict "'()" + pretty v = + case v of + Atom a -> + textStrict a + List ls -> + prettyList $ fmap pretty ls + Numb n -> + integer n + Tape t -> + textStrict "\"" <> textStrict t <> textStrict "\"" + IFun _ -> + textStrict "<internal function>" + Func _ _ -> + textStrict "<lambda function>" + Bool True -> + textStrict "#t" + Bool False -> + textStrict "#f" + Nil -> + textStrict "'()" instance Pretty LispErrorType where pretty err = case err of - NumArgs i args -> - textStrict "number of arguments" - <$$> textStrict "expected" - <+> textStrict (T.pack $ show i) - <$$> textStrict "received" - <+> textStrict (T.pack $ show $ length args) - - - LengthOfList txt i -> - textStrict "length of list in:" - <+> textStrict txt - <$$> textStrict "length:" - <+> textStrict (T.pack $ show i) - - ParseError txt -> - textStrict "cannot parse expr:" - <+> textStrict (T.pack txt) - - TypeMismatch txt expr -> - textStrict "type mismatch:" - <$$> textStrict txt - <$$> pretty expr - - BadSpecialForm txt -> - textStrict "bad special form:" - <$$> textStrict txt - - NotFunction expr -> - textStrict "not a function" - <$$> pretty expr - - UnboundVar txt -> - textStrict "unbound variable:" - <$$> textStrict txt - - Default _ -> - textStrict "default error" - - ReadFileError txt -> - textStrict "error reading file:" - <$$> textStrict txt - - ExpectedList txt -> - textStrict "expected list:" - <$$> textStrict txt + NumArgs i args -> + textStrict "number of arguments" + <$$> textStrict "expected" + <+> textStrict (T.pack $ show i) + <$$> textStrict "received" + <+> textStrict (T.pack $ show $ length args) + LengthOfList txt i -> + textStrict "length of list in:" + <+> textStrict txt + <$$> textStrict "length:" + <+> textStrict (T.pack $ show i) + ParseError txt -> + textStrict "cannot parse expr:" + <+> textStrict (T.pack txt) + TypeMismatch txt expr -> + textStrict "type mismatch:" + <$$> textStrict txt + <$$> pretty expr + BadSpecialForm txt -> + textStrict "bad special form:" + <$$> textStrict txt + NotFunction expr -> + textStrict "not a function" + <$$> pretty expr + UnboundVar txt -> + textStrict "unbound variable:" + <$$> textStrict txt + Default _ -> + textStrict "default error" + ReadFileError txt -> + textStrict "error reading file:" + <$$> textStrict txt + ExpectedList txt -> + textStrict "expected list:" + <$$> textStrict txt instance Pretty LispError where pretty (LispError expr typ) = - textStrict "error evaluating:" + textStrict "error evaluating:" <$$> indent 4 (pretty expr) <$$> pretty typ |