aboutsummaryrefslogtreecommitdiff
path: root/src/Assignment.hs
diff options
context:
space:
mode:
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