diff options
author | Camil Staps | 2017-11-28 11:35:55 +0100 |
---|---|---|
committer | Camil Staps | 2017-11-28 11:35:55 +0100 |
commit | 46645c26debcb0d2eb8ebf5b033fbee37f0957a4 (patch) | |
tree | e6198dbf3381235ea431a77f00c29faa802a28cb /assignment-10/sets.icl | |
parent | Finish programming of assignment 10 (diff) |
Finish assignment 10
Diffstat (limited to 'assignment-10/sets.icl')
-rw-r--r-- | assignment-10/sets.icl | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/assignment-10/sets.icl b/assignment-10/sets.icl index 2a19584..de4a62a 100644 --- a/assignment-10/sets.icl +++ b/assignment-10/sets.icl @@ -77,6 +77,9 @@ for :== For bimapId :: Logical :== Expression Bool :: Ident :== String +fail :: (String -> StateT s (MaybeError String) a) +fail = StateT o const o Error + store :: Ident v -> StateT SetState m v | Monad m & TC v store i v = modify ('M'.put i (dynamic v)) $> v @@ -86,9 +89,6 @@ read i = gets ('M'.get i) >>= \v -> case v of Just d -> fail $ "type error, " <+ typeCodeOfDynamic d <+ " for '" <+ i <+ "'" Nothing -> fail $ "unknown variable '" <+ i <+ "'" -fail :: String -> StateT s (MaybeError String) a -fail e = StateT \_ -> Error e - eval :: (Expression a) -> Sem a | TC a eval (New bm xs) = pure $ bm.map_from xs eval (Elem bm x) = pure $ bm.map_from x @@ -113,6 +113,14 @@ eval (If b t e) = eval b >>= \b -> eval $ if b t e eval (For bm id s e) = bm.map_from <$> (eval s >>= mapM (\x -> store id x >>| eval e)) eval (s :. t) = eval s >>| eval t +/** + * I did not manage to get the iTasks simulator working, because the compiler + * 'cannot build a generic representation of an existential type'. + * I'm sure it would be *possible* by implementing an Editor manually, forcing + * all Bimaps to bimapId and using cast :: a -> b in case of type errors, but + * did not try to do this due to time constraints. + */ + Start = evalStateT (eval stmt) 'M'.newMap where stmt :: Expression [Int] |