From 214c3c0831d473b32f07a1b902caa1d83568177a Mon Sep 17 00:00:00 2001 From: Reg Huijben Date: Tue, 17 Dec 2019 13:20:30 +0100 Subject: [PATCH] tiny cleanup --- week12-reg/week12reg.icl | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/week12-reg/week12reg.icl b/week12-reg/week12reg.icl index 36c70f6..6c9c2de 100644 --- a/week12-reg/week12reg.icl +++ b/week12-reg/week12reg.icl @@ -18,7 +18,7 @@ bm = {f = id, t = id} | MoveUp (BM a Low) (BM b High) | MoveDown (BM a High) (BM b Low) | E.c:(:.) infixl 1 (Action a c) (Action c b) - | Wait (BM a b) (BM a b) + | Wait (BM a b) | WhileContainerBelow (Action High High) :: High = High @@ -29,7 +29,7 @@ unlock = Unlock bm bm up = MoveUp bm bm down = MoveDown bm bm wait :: Action a a -wait = Wait bm bm +wait = Wait bm moveToQuay = MoveToKey bm bm moveToShip = MoveToShip bm bm whileContainerBelow :: (Action High High) -> (Action High High) @@ -59,17 +59,9 @@ initialState = , locked = Nothing } -/* -eval (Lock {f} {t}) st - | st.craneOnQuay   = Res {st & locked = Just (hd st.onQuay), onQuay = tl st.onQuay } - | otherwise        = Res {st & locked = Just (hd st.onShip), onShip = tl st.onShip } -eval (Unlock {f} {t}) st - | st.craneOnQuay    = Res {st & locked = Nothing, onQuay = [fromJust st.locked:st.onQuay] } - | otherwise         = Res {st & locked = Nothing, onShip = [fromJust st.locked:st.onShip] } -*/ eval :: (Action a b) State -> (Res State String) -eval (MoveUp {f} {t}) s = Result {s & craneUp = True} +eval (MoveUp {f} {t}) s = Result {s & craneUp = True} eval (MoveDown {f} {t}) s = Result {s & craneUp = False} eval (Lock {f} {t}) s = if s.craneOnQuay case s.onQuay of @@ -82,9 +74,7 @@ eval (Lock {f} {t}) s = if s.craneOnQuay Just(c) = Error "Cannot lock container, crane occupied" Nothing = Result {s & onShip = xs, locked = (Just x) } [] -> Error "Cannot lock container, none on ship" - //(Error "Cannot lock container, crane not on quay") // should never happen -eval (Unlock {f} {t}) s = if s.craneOnQuay -// (Error "Cannot unlock container, crane not on ship") +eval (Unlock {f} {t}) s = if s.craneOnQuay case s.locked of Just c -> Result {s & onQuay = [c:s.onQuay], locked = Nothing } Nothing -> Error "Cannot unlock container, no container on crane" @@ -98,7 +88,7 @@ eval (MoveToShip {f} {t}) s = if s.craneOnQuay eval (MoveToKey {f} {t}) s = if s.craneOnQuay (Error "Cannot move to quay, crane is already on quay") (Result {s & craneOnQuay = True}) -eval (Wait {f} {t}) s = Result s +eval (Wait {f}) s = Result s eval (:. a b) s = case (eval a s) of Result s -> (eval b s) @@ -141,14 +131,16 @@ print (MoveUp {f} {t}) = ["moveUp"] print (MoveDown {f} {t}) = ["moveDown"] print (Lock {f} {t}) = ["lock"] print (Unlock {f} {t}) = ["unlock"] -print (Wait {f} {t}) = ["wait"] +print (Wait {f} ) = ["wait"] print (:. a b) = print a ++ [":.":"\n": print b ] print (WhileContainerBelow a) = ["whileContainerBelow":"(":"\n": (print a ++ [")"])] t2 :: Action Low Low t2 = lock :. up :. down :. unlock -Start = print loadShip //eval loadShip initialState +//Start = print loadShip +Start = eval loadShip initialState + loadShip = whileContainerBelow ( down:. -- GitLab