From e8e86cea2bffe23961f0a1bea8ee770343894858 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 9 Apr 2020 20:09:43 +0200 Subject: builtin cleaning --- src/Assignment.hs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src/Assignment.hs') 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 -- cgit