Commit 214c3c08 authored by Reg Huijben's avatar Reg Huijben

tiny cleanup

parent 537e0524
...@@ -18,7 +18,7 @@ bm = {f = id, t = id} ...@@ -18,7 +18,7 @@ bm = {f = id, t = id}
| MoveUp (BM a Low) (BM b High) | MoveUp (BM a Low) (BM b High)
| MoveDown (BM a High) (BM b Low) | MoveDown (BM a High) (BM b Low)
| E.c:(:.) infixl 1 (Action a c) (Action c b) | 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) | WhileContainerBelow (Action High High)
:: High = High :: High = High
...@@ -29,7 +29,7 @@ unlock = Unlock bm bm ...@@ -29,7 +29,7 @@ unlock = Unlock bm bm
up = MoveUp bm bm up = MoveUp bm bm
down = MoveDown bm bm down = MoveDown bm bm
wait :: Action a a wait :: Action a a
wait = Wait bm bm wait = Wait bm
moveToQuay = MoveToKey bm bm moveToQuay = MoveToKey bm bm
moveToShip = MoveToShip bm bm moveToShip = MoveToShip bm bm
whileContainerBelow :: (Action High High) -> (Action High High) whileContainerBelow :: (Action High High) -> (Action High High)
...@@ -59,17 +59,9 @@ initialState = ...@@ -59,17 +59,9 @@ initialState =
, locked = Nothing , 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 :: (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 (MoveDown {f} {t}) s = Result {s & craneUp = False}
eval (Lock {f} {t}) s = if s.craneOnQuay eval (Lock {f} {t}) s = if s.craneOnQuay
case s.onQuay of case s.onQuay of
...@@ -82,9 +74,7 @@ eval (Lock {f} {t}) s = if s.craneOnQuay ...@@ -82,9 +74,7 @@ eval (Lock {f} {t}) s = if s.craneOnQuay
Just(c) = Error "Cannot lock container, crane occupied" Just(c) = Error "Cannot lock container, crane occupied"
Nothing = Result {s & onShip = xs, locked = (Just x) } Nothing = Result {s & onShip = xs, locked = (Just x) }
[] -> Error "Cannot lock container, none on ship" [] -> 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
eval (Unlock {f} {t}) s = if s.craneOnQuay
// (Error "Cannot unlock container, crane not on ship")
case s.locked of case s.locked of
Just c -> Result {s & onQuay = [c:s.onQuay], locked = Nothing } Just c -> Result {s & onQuay = [c:s.onQuay], locked = Nothing }
Nothing -> Error "Cannot unlock container, no container on crane" Nothing -> Error "Cannot unlock container, no container on crane"
...@@ -98,7 +88,7 @@ eval (MoveToShip {f} {t}) s = if s.craneOnQuay ...@@ -98,7 +88,7 @@ eval (MoveToShip {f} {t}) s = if s.craneOnQuay
eval (MoveToKey {f} {t}) s = if s.craneOnQuay eval (MoveToKey {f} {t}) s = if s.craneOnQuay
(Error "Cannot move to quay, crane is already on quay") (Error "Cannot move to quay, crane is already on quay")
(Result {s & craneOnQuay = True}) (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 eval (:. a b) s = case (eval a s) of
Result s -> (eval b s) Result s -> (eval b s)
...@@ -141,14 +131,16 @@ print (MoveUp {f} {t}) = ["moveUp"] ...@@ -141,14 +131,16 @@ print (MoveUp {f} {t}) = ["moveUp"]
print (MoveDown {f} {t}) = ["moveDown"] print (MoveDown {f} {t}) = ["moveDown"]
print (Lock {f} {t}) = ["lock"] print (Lock {f} {t}) = ["lock"]
print (Unlock {f} {t}) = ["unlock"] print (Unlock {f} {t}) = ["unlock"]
print (Wait {f} {t}) = ["wait"] print (Wait {f} ) = ["wait"]
print (:. a b) = print a ++ [":.":"\n": print b ] print (:. a b) = print a ++ [":.":"\n": print b ]
print (WhileContainerBelow a) = ["whileContainerBelow":"(":"\n": (print a ++ [")"])] print (WhileContainerBelow a) = ["whileContainerBelow":"(":"\n": (print a ++ [")"])]
t2 :: Action Low Low t2 :: Action Low Low
t2 = lock :. up :. down :. unlock t2 = lock :. up :. down :. unlock
Start = print loadShip //eval loadShip initialState //Start = print loadShip
Start = eval loadShip initialState
loadShip = whileContainerBelow ( loadShip = whileContainerBelow (
down:. down:.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment