aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Helper.hs
diff options
context:
space:
mode:
authorMarvin Borner2022-08-07 00:06:20 +0200
committerMarvin Borner2022-08-07 00:08:17 +0200
commitd2a5d69f42d74e8382ca29c8c166eba3a79d20d5 (patch)
tree01e3fa75173e99dc78b516050079acb1d1b11a0d /src/Helper.hs
parent4ec1d9312839bf73ad80a4555e5c53e0b388c86a (diff)
Progress
As always - very descriptive. I've been busy with exams but from now on I'll be working on bruijn again.
Diffstat (limited to 'src/Helper.hs')
-rw-r--r--src/Helper.hs13
1 files changed, 11 insertions, 2 deletions
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