started with 11
authorMart Lubbers <mart@martlubbers.net>
Tue, 1 Dec 2015 15:46:43 +0000 (16:46 +0100)
committerMart Lubbers <mart@martlubbers.net>
Tue, 1 Dec 2015 15:46:43 +0000 (16:46 +0100)
a11/assignment11.pdf [new file with mode: 0644]
a11/mart/Makefile [new file with mode: 0644]
a11/mart/skeleton11.icl [new file with mode: 0644]

diff --git a/a11/assignment11.pdf b/a11/assignment11.pdf
new file mode 100644 (file)
index 0000000..32a1bda
Binary files /dev/null and b/a11/assignment11.pdf differ
diff --git a/a11/mart/Makefile b/a11/mart/Makefile
new file mode 100644 (file)
index 0000000..5903bd5
--- /dev/null
@@ -0,0 +1,14 @@
+CLEANEXES:=skeleton11
+CLM:=clm
+CLMFLAGS:=-IL ../lib/StdLib -IL ../lib/Generics
+
+all: $(CLEANEXES)
+
+%.exe: %.prj
+       $(CPM) project $< build
+
+%: %.icl
+       $(CLM) $(CLMFLAGS) $(basename $<) -o $@
+
+clean:
+       $(RM) -r $(CLEANEXES) Clean\ System\ Files
diff --git a/a11/mart/skeleton11.icl b/a11/mart/skeleton11.icl
new file mode 100644 (file)
index 0000000..829a221
--- /dev/null
@@ -0,0 +1,36 @@
+module skeleton11
+
+import StdEnv
+
+:: Prog :== [Instr]
+
+:: Instr = Write Expr
+
+:: Expr = Int   Int
+        | Plus  Expr Expr
+        | Times Expr Expr
+        | Read
+
+possibleResults :: [Prog] -> [Int]
+possibleResults x = produce (map (map (\(Write x).eval x)) x) 0
+
+produce :: [[Int->Int]] Int -> [Int]
+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
+
+
+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)