aboutsummaryrefslogtreecommitdiff
path: root/src/Assignment.hs
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-04-09 20:09:43 +0200
committerCharles <sircharlesaze@gmail.com>2020-04-09 20:09:43 +0200
commite8e86cea2bffe23961f0a1bea8ee770343894858 (patch)
tree2223ba98108ea98b86be4ee104a682109c56b74d /src/Assignment.hs
parent9a4cf15fc0e724e6bc93c6530b47ca45836da5ba (diff)
downloadcomputorv2-e8e86cea2bffe23961f0a1bea8ee770343894858.tar.gz
computorv2-e8e86cea2bffe23961f0a1bea8ee770343894858.tar.bz2
computorv2-e8e86cea2bffe23961f0a1bea8ee770343894858.zip
builtin cleaning
Diffstat (limited to 'src/Assignment.hs')
-rw-r--r--src/Assignment.hs25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/Assignment.hs b/src/Assignment.hs
index 51e619a..2dc7aef 100644
--- a/src/Assignment.hs
+++ b/src/Assignment.hs
@@ -1,23 +1,42 @@
module Assignment where
+import Data.List
import qualified Expr as E
data Assignment
= Variable String E.Expr
| Function String String E.Expr
- deriving (Eq)
+
+instance Eq Assignment where
+ (Variable n1 _) == (Variable n2 _) = n1 == n2
+ (Function n1 _ _) == (Function n2 _ _) = n1 == n2
+ _ == _ = False
name :: Assignment -> String
name (Variable n _) = n
name (Function n _ _) = n
+-- data Context a = Context { vars :: [Assignment], payload :: a }
type Context = [Assignment]
+-- instance Functor Context where
+-- fmap f (Context as x) = Context as (f x)
+--
+-- instance Applicative Context where
+-- pure x = Context [] x
+-- (Context a1 f) <*> (Context a2 x) = Context (a1 `union` a2) (f x)
+--
+-- instance Monad Context where
+-- return = pure
+-- (Context a1 x) >>= f = Context (vars res `union` a1) (payload res)
+-- where res = f x
+
+
update :: Context -> Assignment -> Context
update context a
- | name a `elem` map name context = map replaceIf context
+ | a `elem` context = map replaceIf context
| otherwise = a:context
- where replaceIf a' = if name a' == name a then a else a'
+ where replaceIf a' = if a' == a then a else a'
get :: Context -> String -> Maybe Assignment
get context n = case found of [] -> Nothing