From e971a7991925e3d394732b4c8cbd24e02603c2a8 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Wed, 23 Sep 2015 10:31:26 +0200 Subject: [PATCH] done except that tuple map2 crashes --- a3/mart/Makefile | 21 +++++++++++++++ a3/mart/iTasksTest.prj | 2 +- a3/mart/skeleton3a.icl | 2 +- a3/mart/skeleton3a_wt.icl | 4 ++- a3/mart/skeleton3b.icl | 57 +++++++++++++++++++++++++++++++++++---- 5 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 a3/mart/Makefile diff --git a/a3/mart/Makefile b/a3/mart/Makefile new file mode 100644 index 0000000..0e68e12 --- /dev/null +++ b/a3/mart/Makefile @@ -0,0 +1,21 @@ +CLEANEXES:=skeleton3a skeleton3b skeleton3a_wt +ITASKSPRJS:=iTasksTest.exe +CLM:=clm +CPM:=cpm +CLMFLAGS:=-IL ../lib/StdLib -IL ../lib/Generics + +all: $(CLEANEXES) $(ITASKSPRJS) + +%.exe: %.prj + $(CPM) project $< build + +%: %.icl + $(CLM) $(CLMFLAGS) $(basename $<) -o $@ + +clean: + $(RM) -r \ + $(CLEANEXES) \ + $(addsuffix .exe,$(basename $(ITASKSPRJS))) \ + Clean\ System\ Files \ + sapl \ + $(addsuffix -data,$(basename $(ITASKSPRJS))) diff --git a/a3/mart/iTasksTest.prj b/a3/mart/iTasksTest.prj index df6ac2a..b1da31f 100644 --- a/a3/mart/iTasksTest.prj +++ b/a3/mart/iTasksTest.prj @@ -2,7 +2,7 @@ Version: 1.4 Global ProjectRoot: . Target: iTasks - Exec: {Project}/test.exe + Exec: {Project}/iTasksTest.exe CodeGen CheckStacks: False CheckIndexes: True diff --git a/a3/mart/skeleton3a.icl b/a3/mart/skeleton3a.icl index b741436..e96cd96 100644 --- a/a3/mart/skeleton3a.icl +++ b/a3/mart/skeleton3a.icl @@ -246,7 +246,7 @@ instance map2 (,) where Start = ( map1 fac aTree, map1 fac aList, - map2 fac fac (aList, aTree), +// map2 fac fac (aList, aTree), map1 (\x.(x, fac x)) aList ) where diff --git a/a3/mart/skeleton3a_wt.icl b/a3/mart/skeleton3a_wt.icl index 2e893ec..91025af 100644 --- a/a3/mart/skeleton3a_wt.icl +++ b/a3/mart/skeleton3a_wt.icl @@ -1,4 +1,4 @@ -module skeleton3a +module skeleton3a_wt /* Advanced Programming. @@ -215,3 +215,5 @@ instance eq2 EITHER where instance eq0 [a] | eq0 a where eq0 l m = eq1 eq0 l m instance eq1 [] where eq1 f l m = eq2 (eq1 eq0) (eq1 (eq2 f (eq1 f))) (fromList l) (fromList m) + +Start = "Hi" diff --git a/a3/mart/skeleton3b.icl b/a3/mart/skeleton3b.icl index 5753ddc..a0675f9 100644 --- a/a3/mart/skeleton3b.icl +++ b/a3/mart/skeleton3b.icl @@ -16,6 +16,7 @@ generic show_ a :: a [String] -> [String] show_{|Int|} i c = [toString i:c] show_{|Bool|} b c = [toString b:c] +show_{|UNIT|} _ c = c show a = show_{|*|} a [] @@ -48,8 +49,54 @@ test x Just (y,[]) = x === y _ = False -/**************** End Prelude, add all new code below this line *************************/ - -//------------------ tests -------------- - -Start = and [test b \\ b <- [False, True]] +/***** End Prelude, add all new code below this line *************************/ +//Show stuff +show_{|OBJECT|} f (OBJECT x) c = f x c +show_{|CONS of {gcd_name, gcd_arity}|} f (CONS x) c +| gcd_arity == 0 = [gcd_name:f x c] +| otherwise = ["(":gcd_name:f x [")":c]] +show_{|PAIR|} f1 f2 (PAIR x1 x2) c = f1 x1 (f2 x2 c) +show_{|EITHER|} f _ (LEFT x) c = f x c +show_{|EITHER|} _ f (RIGHT x) c = f x c +show_{|(,)|} f1 f2 (x1, x2) c = ["("] ++ f1 x1 [",":f2 x2 c]++[")"] + +derive show_ T, [], Color, Tree + +//Parse stuff (monads would make this more neat) +parse{|Int|} [i:r] = Just (toInt i, r) +parse{|Int|} _ = Nothing +parse{|UNIT|} r = Just (UNIT, r) +parse{|OBJECT|} f r = case f r of + Just (x, r) = Just (OBJECT x, r) + _ = Nothing +parse{|CONS of {gcd_name, gcd_arity}|} f r +| gcd_arity == 0 = case r of + [gcd_name:r] = case f r of + Just (x, r) = Just (CONS x, r) + _ = Nothing + _ = Nothing +| otherwise = case r of + ["(",gcd_name:r] = case f r of + Just (x, r) = Just (CONS x, r % (0, (length r) - 2)) + _ = Nothing + _ = Nothing +parse{|PAIR|} f1 f2 r = case f1 r of + Just (x1, r) = case f2 r of + Just (x2, r) = Just (PAIR x1 x2, r) + _ = Nothing + _ = Nothing +parse{|EITHER|} f1 f2 r = case f2 r of + Just (x, r) = Just (RIGHT x, r) + _ = case f1 r of + Just (x, r) = Just (LEFT x, r) + _ = Nothing +parse{|(,)|} f1 f2 ["(":r] = case f1 r of + Just (x1, r) = case r of + [",":r] = case f2 r of + Just (x2, r) = Just ((x1, x2), r % (0, (length r) - 2)) + _ = Nothing + _ = Nothing + _ = Nothing + +derive parse T, [], Color, Tree +Start = show 42 -- 2.20.1