Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Advanced Programming
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Job Cuppen
Advanced Programming
Commits
214c3c08
Commit
214c3c08
authored
Dec 17, 2019
by
Reg Huijben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tiny cleanup
parent
537e0524
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
17 deletions
+9
-17
week12-reg/week12reg.icl
week12-reg/week12reg.icl
+9
-17
No files found.
week12-reg/week12reg.icl
View file @
214c3c08
...
...
@@ -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
:.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment