repositories
/
ap2015.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
1d3c02e
)
final as11
author
Mart Lubbers
<mart@martlubbers.net>
Tue, 1 Dec 2015 17:39:45 +0000
(18:39 +0100)
committer
Mart Lubbers
<mart@martlubbers.net>
Tue, 1 Dec 2015 17:39:45 +0000
(18:39 +0100)
a11/mart/skeleton11.icl
patch
|
blob
|
history
diff --git
a/a11/mart/skeleton11.icl
b/a11/mart/skeleton11.icl
index
829a221
..
2de15e5
100644
(file)
--- a/
a11/mart/skeleton11.icl
+++ b/
a11/mart/skeleton11.icl
@@
-3,34
+3,39
@@
module skeleton11
import StdEnv
:: Prog :== [Instr]
import StdEnv
:: Prog :== [Instr]
-
-:: Instr = Write Expr
-
+:: Instr = Write Expr | Atomic [Instr]
:: Expr = Int Int
| Plus Expr Expr
| Times Expr Expr
| Read
possibleResults :: [Prog] -> [Int]
:: Expr = Int Int
| Plus Expr Expr
| Times Expr Expr
| Read
possibleResults :: [Prog] -> [Int]
-possibleResults x = produce
(map (map (\(Write x).eval x)) x)
0
+possibleResults x = produce
x
0
-produce :: [
[Int->Int]
] Int -> [Int]
+produce :: [
Prog
] Int -> [Int]
produce x i
| all (isEmpty) x = [i]
produce x i
| all (isEmpty) x = [i]
-= flatten [produce (updateAt idx ys x) (y i)\\(idx, [y:ys])<-zip2 [0..] x]
-
-eval :: Expr Int -> Int
-eval (Int i) s = i
-eval (Plus e1 e2) s = eval e1 s + eval e2 s
-eval (Times e1 e2) s = eval e1 s * eval e2 s
-eval Read s = s
+= flatten [produce (updateAt idx ys x) (eval y i)\\(idx, [y:ys])<-zip2 [0..] x]
+eval :: Instr Int -> Int
+eval (Write (Int i)) s = i
+eval (Write (Plus e1 e2)) s = eval (Write e1) s + eval (Write e2) s
+eval (Write (Times e1 e2)) s = eval (Write e1) s * eval (Write e2) s
+eval (Write Read) s = s
+eval (Atomic x) s = hd (produce [x] s)
prog0 = [Write (Int 12), Write (Plus Read (Int 1))]
prog1 = [Write (Times Read (Int 2))]
test0 = [prog0]
test1 = [prog0, prog1]
prog0 = [Write (Int 12), Write (Plus Read (Int 1))]
prog1 = [Write (Times Read (Int 2))]
test0 = [prog0]
test1 = [prog0, prog1]
-Start = (
- possibleResults test0,
- possibleResults test1)
+Start = 0
+/* Writing the semantics in clean is advantageous because you can execute the
+ * code, have it type checked and it is very readable for a programmer.
+ *
+ * Disadvantages might be that it might be harder to prove stuff. Also
+ * mathematic notation is generally more concise.
+ *
+ * Some things are modelled very difficultly in a functional language. For
+ * example file io, parallel processes or user interaction.
+*/