From d2a5d69f42d74e8382ca29c8c166eba3a79d20d5 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 7 Aug 2022 00:06:20 +0200 Subject: Progress As always - very descriptive. I've been busy with exams but from now on I'll be working on bruijn again. --- src/Helper.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/Helper.hs') diff --git a/src/Helper.hs b/src/Helper.hs index 33c0855..e1b3819 100644 --- a/src/Helper.hs +++ b/src/Helper.hs @@ -3,6 +3,7 @@ module Helper where import Control.Monad.State import qualified Data.BitString as Bit import qualified Data.ByteString as Byte +import Data.List data Error = UndeclaredFunction String | DuplicateFunction String | InvalidIndex Int | FatalError String instance Show Error where @@ -14,7 +15,7 @@ type Failable = Either Error data Expression = Bruijn Int | Variable String | Abstraction Expression | Application Expression Expression deriving (Ord, Eq) -data Instruction = Define String Expression [Instruction] | Evaluate Expression | Comment String | Import String String | Test Expression Expression +data Instruction = Define String Expression [Instruction] | Evaluate Expression | Comment | Import String String | Test Expression Expression deriving (Show) instance Show Expression where show (Bruijn x ) = "\ESC[31m" <> show x <> "\ESC[0m" @@ -24,9 +25,17 @@ instance Show Expression where "\ESC[33m(\ESC[0m" <> show exp1 <> " " <> show exp2 <> "\ESC[33m)\ESC[0m" type EnvDef = (String, Expression) -type Environment = [EnvDef] +data Environment = Environment [(EnvDef, Environment)] type Program = State Environment +instance Semigroup Environment where + (Environment e1) <> (Environment e2) = Environment $ e1 <> e2 + +instance Show Environment where + show (Environment env) = intercalate "\n" $ map + (\((n, f), s) -> "\t" <> show n <> ": " <> show f <> " - " <> show s) + env + --- listify :: [Expression] -> Expression -- cgit v1.2.3