Commit 6040c8b5 authored by Job Cuppen's avatar Job Cuppen

added output as comments

parent c62600f8
......@@ -10,7 +10,7 @@ module ex1
Use Basic Values Only as conclose option for a nicer output.
*/
import StdEnv, StdMaybe
import StdEnv, StdMaybe, StdDebug
class unitDecidable a where
isUnit :: a -> Bool
......@@ -115,17 +115,22 @@ instance serialize0 (CONS a) | serialize0 a where
Nothing -> Nothing
read0 _ = Nothing
instance serialize1 CONS where
/*
write1 f (CONS str a) c
| (isUnit a) = [str : f a c]
| otherwise = ["[":str:(f a ["]":c])]
read1 f ["[":str:r] = case f r of
read1 f ["[":str:r] = case f r of
Just (a, ["]":r]) -> Just(CONS str a, r)
Just (a, r) -> Nothing
Nothing -> Nothing
read1 f [str:r] = case f r of
Just (a, r) -> Just(CONS str a, r)
Nothing -> Nothing
*/
instance serialize1 CONS where
write1 f (CONS str a) c = []
read1 _ _ = Nothing
......@@ -250,6 +255,26 @@ Start =
,test (Head,(7,[Tail]))
,["End of the tests.\n"]
]
/*
Oke, write produces: True
Oke, write produces: False
Oke, write produces: 0
Oke, write produces: 123
Oke, write produces: -36
Oke, write produces: [Cons42Nil]
Oke, write produces: [Cons0[Cons1[Cons2[Cons3[Cons4Nil]]]]]
Oke, write produces: [Cons[ConsTrueNil][ConsNilNil]]
Oke, write produces: [Cons[Cons[Cons1Nil]Nil][Cons[Cons[Cons2Nil][Cons[Cons3[Cons4Nil]]Nil]][Cons[ConsNilNil]Nil]]]
Oke, write produces: [BinLeafTrueLeaf]
Oke, write produces: [Cons[Bin[BinLeaf[Cons1Nil]Leaf][Cons2Nil][BinLeaf[Cons3Nil][BinLeaf[Cons4[Cons5Nil]]Leaf]]]Nil]
Oke, write produces: [Cons[Bin[BinLeaf[Cons1Nil]Leaf][Cons2Nil][BinLeaf[Cons3Nil][Bin[BinLeaf[Cons4[Cons5Nil]]Leaf][Cons6[Cons7Nil]][BinLeaf[Cons8[Cons9Nil]]Leaf]]]]Nil]
Oke, write produces: Head
Wrong result: Head, write produces: Tail
Oke, write produces: (7,True)
Wrong result: (Head,(7,[ConsHeadNil])), write produces: (Head,(7,[ConsTailNil]))
End of the tests.
*/
test :: a -> [String] | serialize0, == a
test a =
......
......@@ -102,7 +102,6 @@ Start =
,test 0
,test 123
,test -36
,test (7,True)
,test [42]
,test [0..4]
,test [[True],[]]
......@@ -117,6 +116,26 @@ Start =
,["End of the tests.\n"]
]
/*
Oke, write produces: True
Oke, write produces: False
Oke, write produces: 0
Oke, write produces: 123
Oke, write produces: -36
Oke, write produces: (_Cons42_Nil)
Oke, write produces: (_Cons0(_Cons1(_Cons2(_Cons3(_Cons4_Nil)))))
Oke, write produces: (_Cons(_ConsTrue_Nil)(_Cons_Nil_Nil))
Oke, write produces: (_Cons(_Cons(_Cons1_Nil)_Nil)(_Cons(_Cons(_Cons2_Nil)(_Cons(_Cons3(_Cons4_Nil))_Nil))(_Cons(_Cons_Nil_Nil)_Nil)))
Oke, write produces: (BinLeafTrueLeaf)
Oke, write produces: (_Cons(Bin(BinLeaf(_Cons1_Nil)Leaf)(_Cons2_Nil)(BinLeaf(_Cons3_Nil)(BinLeaf(_Cons4(_Cons5_Nil))Leaf)))_Nil)
Oke, write produces: (_Cons(Bin(BinLeaf(_Cons1_Nil)Leaf)(_Cons2_Nil)(BinLeaf(_Cons3_Nil)(Bin(BinLeaf(_Cons4(_Cons5_Nil))Leaf)(_Cons6(_Cons7_Nil))(BinLeaf(_Cons8(_Cons9_Nil))Leaf))))_Nil)
Oke, write produces: Head
Oke, write produces: Tail
Oke, write produces: (7,True)
Oke, write produces: (Head,(7,(_ConsTail_Nil)))
End of the tests.
*/
test :: a -> [String] | serialize, == a
test a =
(if (isJust r)
......
......@@ -34,12 +34,15 @@ tuplize n = (n, fac n)
// apply the factorial to all elements of t
//Start = gMap{|*->*|} fac t
// (Bin (Bin Leaf 1 Leaf) 2 (Bin (Bin Leaf 6 Leaf) 24 Leaf))
// turn each integer i in list l to a tuple (i, fac i);
//Start = gMap{|*->*|} tuplize l
// [(1,1),(2,2),(3,6),(4,24),(5,120),(6,720),(7,5040)]
// apply the factorial function to all integers in (l, t).
//Start = gMap{|*->*->*|} (gMap{|*->*|} fac) (gMap{|*->*|} fac) (l,t)
// ([1,2,6,24,120,720,5040],(Bin (Bin Leaf 1 Leaf) 2 (Bin (Bin Leaf 6 Leaf) 24 Leaf)))
generic gEq a :: !a !a -> Bool
gEq{|Int|} x y = x == y
......@@ -62,9 +65,11 @@ derive gEq [], (), (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)
// compute the equality of [1,2] and [1,2];
//Start = gEq{|*->*|} gEq{|*|} [1,2] [1,2]
// True
// compute the equality of [1,2] and [2,3];
//Start = gEq{|*->*|} gEq{|*|} [1,2] [2,3]
// False
// compute the equality of [1,2] and [2,3]
// where you use the less-then operator <
......@@ -72,4 +77,5 @@ derive gEq [], (), (,), (,,), (,,,), (,,,,), (,,,,,), (,,,,,,), (,,,,,,,)
// This last item is only to show you the
// possibilities of the generic mechanism,
// it is not necessarily a recommended way of working.
//Start = gEq{|*->*|} (\x y-> not (x<y) && not (y<x)) [1,2] [2,3]
\ No newline at end of file
Start = gEq{|*->*|} (\x y-> not (x<y) && not (y<x)) [1,2] [2,3]
// False
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment