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
b7f48832
Commit
b7f48832
authored
Dec 09, 2019
by
Reg Huijben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Got statements working, lost will to live
parent
a1d6b4e1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
157 additions
and
14 deletions
+157
-14
week11-reg/week11_reg.icl
week11-reg/week11_reg.icl
+157
-14
No files found.
week11-reg/week11_reg.icl
View file @
b7f48832
...
...
@@ -54,8 +54,8 @@ instance pure Res where
int
::
Int
->
Element
int
i
=
pure
i
s
ize
::
Set
->
Element
s
ize
se
=
fmap
length
se
S
ize
::
Set
->
Element
S
ize
se
=
fmap
length
se
instance
+
Element
where
(+)
(
Sem
a
)
(
Sem
b
)
=
Sem
\
s
.
case
a
s
of
...
...
@@ -110,13 +110,116 @@ instance ==. Set where
instance
==.
Element
where
(==.)
a
b
=
(==)
<$>
a
<*>
b
//:: Expr = New [Int]
// | Int Int
// | Var Ident
// | Size Set
// | (+.) infixl 6 Expr Expr
//class IF b where
// IF :: (Sem Bool) (Sem b) (Sem b) -> (Sem b)
/* instance IF a where
IF (Sem cond) (Sem st1) (Sem st2) = Sem \s. case cond s of
(Res a, s) = case (if a (st1) (st2) s) of
(Res f, s) = (Res f, s)
(Err e,s) = (Err e, s)
(Err e,s) = (Err e, s) */
class
If
a
b
where
If
::
(
Sem
Bool
)
(
Sem
a
)
(
Sem
b
)
->
(
Sem
())
instance
If
a
b
where
If
(
Sem
cond
)
(
Sem
st1
)
(
Sem
st2
)
=
Sem
\
s
.
case
cond
s
of
(
Res
a
,
s
)
=
if
a
(
case
st1
s
of
(
Res
_,
s
)
=
(
Res
(),
s
)
(
Err
e
,
s
)
=
(
Err
e
,
s
)
)
(
case
st2
s
of
(
Res
_,
s
)
=
(
Res
(),
s
)
(
Err
e
,
s
)
=
(
Err
e
,
s
)
)
(
Err
e
,
s
)
=
(
Err
e
,
s
)
/*Logical
/*
For :: Ident Set (Sem a) -> (Sem ())
For i (Sem st) (Sem stmt) = Sem \s. case st s of
(Res [a:aa], s) = case stmt (State ('Map'.put i (I a) s)) of // a is [Int]
(Res _, s) = case (For i (pure aa) (Sem stmt)) s of
(Res _,s)= (Res (),s)
(Err e,s) = (Err e, s)
(Err e,s) = (Err e, s)
(Res [], s) = (Res (),s) // a is [Int]
(Err e,s) = (Err e, s)
*/
iif :: Logical Statement Statement -> Bool
iif log st1 st2 = False
/*
For :: Ident Set (Sem a) -> (Sem ())
For i (Sem st) (Sem stmt) = Sem \s. case st s of
(Res [a:aa], s) = let (Sem fff, st) = (For i (pure aa) (Sem stmt)) in
case stmt (State ('Map'.put i (I a) st)) of // a is [Int]
(Res _, s) = case fff s of
(Res _,s)= (Res (),s)
(Err e,s) = (Err e, s)
(Err e,s) = (Err e, s)
(Res [], s) = (Res (),s) // a is [Int]
(Err e,s) = (Err e, s)
*/
/*
For :: Ident Set (Sem a) -> (Sem ())
For i (Sem st) (Sem stmt) = Sem \s. case st s of // eval the set
(Res [a:aa], s) = case stmt (\s .State ('Map'.put i (I a) s)) s of // eval the statement after the assignment
(Res _, s) = let (Sem fff) = (For i (pure aa) (Sem stmt)) in
case fff s of // eval the rest of the statements
(Res (), s) = (Res (),s)
(Err e,s) = (Err e, s)
(Err e,s) = (Err e, s)
(Res [], s) = (Res (),s) // a is [Int]
(Err e,s) = (Err e, s)
*/
//(=.) infixl 2 :: Ident (Sem a) -> (Sem a)
// This sucks, surely there is a sane way to do this? jfc
For
::
Ident
Set
(
Sem
a
)
->
(
Sem
())
For
i
(
Sem
st
)
(
Sem
stmt
)
=
Sem
\
s
.
case
st
s
of
(
Res
[
a
:
aa
],
State
s
)
=
case
stmt
(
State
('
Map
'.
put
i
(
I
a
)
s
))
of
(
Res
_,
s
)
=
let
(
Sem
f
)
=
(
For
i
(
pure
aa
)
(
Sem
stmt
))
in
f
s
(
Err
e
,
s
)
=
(
Err
e
,
s
)
(
Res
[],
s
)
=
(
Res
(),
s
)
(
Err
e
,
s
)
=
(
Err
e
,
s
)
While
::
(
Sem
Bool
)
(
Sem
a
)
->
(
Sem
())
While
(
Sem
bl
)
(
Sem
stmt
)
=
Sem
\
s
.
case
bl
s
of
(
Res
True
,
s
)
=
case
stmt
s
of
(
Res
_,
s
)
=
let
(
Sem
f
)
=
(
While
(
Sem
bl
)
(
Sem
stmt
))
in
f
s
(
Err
e
,
s
)
=
(
Err
e
,
s
)
(
Res
False
,
s
)
=
(
Res
(),
s
)
(
Err
e
,
s
)
=
(
Err
e
,
s
)
// Sem st >>= \ x. Sem \s. (Err x, s)
(
In
)
infix
4
::
(
Element
)
(
Set
)
->
(
Sem
Bool
)
(
In
)
(
Sem
e
)
(
Sem
st
)
=
Sem
\
s
.
case
e
s
of
(
Res
a
,
s
)
=
case
st
s
of
(
Res
theSet
,
s
)
=
(
Res
(
elem
a
theSet
),
s
)
(
Err
e
,
s
)
=
(
Err
e
,
s
)
(
Err
e
,
s
)
=
(
Err
e
,
s
)
/*Logical
*/
class
=.
a
where
(=.)
infixl
2
::
Ident
(
Sem
a
)
->
(
Sem
a
)
...
...
@@ -134,28 +237,44 @@ instance =. Int where
(
Err
e
,
s
)
=
(
Err
e
,
s
)
//(=.) i v = Sem \(State s). (pure v, State ('Map'.put i v s))
class
Var
a
where
v
ar
::
Ident
->
(
Sem
a
)
V
ar
::
Ident
->
(
Sem
a
)
instance
Var
Int
where
v
ar
i
=
Sem
\(
State
s
)
.
case
('
Map
'.
get
i
s
)
of
V
ar
i
=
Sem
\(
State
s
)
.
case
('
Map
'.
get
i
s
)
of
(
Just
a
)
->
case
a
of
(
I
i
)
=
(
pure
i
,
State
s
)
(
S
st
)
=
(
Err
(
"Expected int, found set "
+++
(
toString
st
)),
State
s
)
_
->
(
Err
(
"Could not find variable "
+++
i
),
State
s
)
instance
Var
[
Int
]
where
v
ar
i
=
Sem
\(
State
s
)
.
case
('
Map
'.
get
i
s
)
of
V
ar
i
=
Sem
\(
State
s
)
.
case
('
Map
'.
get
i
s
)
of
(
Just
a
)
->
case
a
of
(
I
i
)
=
(
Err
(
"Expected set, found int "
+++
(
toString
i
)),
State
s
)
(
S
st
)
=
(
pure
st
,
State
s
)
_
->
(
Err
(
"Could not find variable "
+++
i
),
State
s
)
(<=.)
infix
4
::
Element
Element
->
Sem
Bool
(<=.)
e1
e2
=
(<=)
<$>
e1
<*>
e2
(||.)
infixr
2
::
(
Sem
Bool
)
(
Sem
Bool
)
->
Sem
Bool
(||.)
e1
e2
=
(||)
<$>
e1
<*>
e2
(&&.)
infixr
2
::
(
Sem
Bool
)
(
Sem
Bool
)
->
Sem
Bool
(&&.)
e1
e2
=
(&&)
<$>
e1
<*>
e2
Not
::
(
Sem
Bool
)
->
(
Sem
Bool
)
Not
s
=
not
<$>
s
TRUE
::
(
Sem
Bool
)
TRUE
=
pure
True
FALSE
::
(
Sem
Bool
)
FALSE
=
pure
False
//(==.) infixr 3 :: Set Set -> Sem Bool
//(==.) a b = (equalSet) <$> a <*> b
...
...
@@ -221,9 +340,33 @@ zfr = pure [9,2,3]
//zoefs = (zfl) ==. (zfr)
zoefs
=
"A"
=.
(
zfr
)
//zoefs = int 8 ==. int 8
zoefss
=
var
"A"
+
var
"A"
//pure [1,2,3]
zoefss
=
Var
"A"
+
int
8
//var "A" //pure [1,2,3]
New
::
[
Int
]
->
Set
New
s
=
pure
s
Elem
::
Int
->
Element
Elem
i
=
int
i
hetProgramma
=
If
(
Elem
4
In
New
[
1
,
2
,
3
])
(
"A"
=.
New
[
6
])
(
"B"
=.
Elem
6
)
hetProgramma2
=
If
(
New
[
4
]
==.
New
[
1
,
2
,
3
])
(
"A"
=.
New
[
6
])
(
"B"
=.
Elem
6
)
hetProgramma3
=
If
((
Size
(
New
[
4
]))
==.
Elem
1
)
(
"A"
=.
New
[
6
])
(
"B"
=.
Elem
6
)
hetProgramma4
=
Elem
3
In
New
[
7
]
||.
Elem
8
<=.
Elem
7
//Start = equalSet [9,2,3] [9,3,2,1] || equalSet [9,3,2,1] [9,2,3]
//Start = let ((a,b) = evl zoefs emptyState) in evl zoefss b
Start
=
evl
zoefss
(
snd
(
evl
zoefs
emptyState
)
)
\ No newline at end of file
//Start = evl zoefss (snd (evl zoefs emptyState) )
//Start = evl (IF (pure True) ("A" =. zfr) ("B" =. zfr) ) emptyState
//Start = evl (For "A" (New [1,2,3,8]) (If (Var "A" ==. Elem 3) ("Z" =. Var "A" + Elem 0) (Elem 8))) emptyState
someSt
=
State
('
Map
'.
put
"A"
(
I
0
)
'
Map
'.
newMap
)
Start
=
evl
(
While
(
Var
"A"
<=.
Elem
3
)
(
"A"
=.
(
Var
"A"
+
Elem
1
)))
someSt
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