From 592dd55a70bcf3a159c32f07c698b3cc39b0d02a Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 2 Oct 2017 20:13:38 +0200 Subject: Cleanup bootstrap --- assignment-4/serialize4.icl | 101 ++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 51 deletions(-) (limited to 'assignment-4/serialize4.icl') diff --git a/assignment-4/serialize4.icl b/assignment-4/serialize4.icl index 10026eb..edbcc32 100644 --- a/assignment-4/serialize4.icl +++ b/assignment-4/serialize4.icl @@ -3,13 +3,13 @@ module serialize4 import StdEnv, StdMaybe, monad /* - Pieter Koopman, pieter@cs.ru.nl - Advanced Programming, week 4, 2017 - - import StdMaybe from Libraries/StdLib - use StdEnv or StdEnv 64 - use Basic Values Only as conclose option for a nicer output. -*/ + * Pieter Koopman, pieter@cs.ru.nl + * Advanced Programming, week 4, 2017 + * + * import StdMaybe from Libraries/StdLib + * use StdEnv or StdEnv 64 + * use Basic Values Only as conclose option for a nicer output. + */ // --- @@ -63,14 +63,14 @@ pred f = fail :: Write a :== a -> Serialize String :: Read a :== Serialize a - + class serialize a | isUNIT a where - write :: a -> Serialize String - read :: Serialize a + write :: a -> Serialize String + read :: Serialize a class serialize1 t where - write1 :: (Write a) (t a) -> Serialize String - read1 :: (Read a) -> Serialize (t a) + write1 :: (Write a) (t a) -> Serialize String + read1 :: (Read a) -> Serialize (t a) class serializeCONS a where writeCons :: (Write a) (CONS a) -> Serialize String @@ -85,8 +85,8 @@ instance isUNIT UNIT where isUNIT _ = True instance isUNIT a where isUNIT _ = False instance serialize Bool where - write b = fail - read = fail + write b = fail + read = fail instance serialize Int where write i = fail @@ -103,19 +103,19 @@ instance serialize UNIT where instance serializeCONS UNIT where writeCons wa (CONS name a) = fail readCons name ra = fail - + instance serializeCONS a where writeCons wa (CONS name a) = fail readCons name ra =fail - + instance serialize2 EITHER where - write2 wa wb (LEFT a) = fail - write2 wa wb (RIGHT b) = fail - read2 ra rb = fail + write2 wa wb (LEFT a) = fail + write2 wa wb (RIGHT b) = fail + read2 ra rb = fail instance serialize2 PAIR where - write2 wa wb (PAIR a b) = fail - read2 ra rb = fail + write2 wa wb (PAIR a b) = fail + read2 ra rb = fail // --- @@ -198,35 +198,34 @@ instance serialize (a,b) | serialize a & serialize b where // --- -Start = - [test True - ,test False - ,test 0 - ,test 123 - ,test -36 - ,test Head - ,test Tail - ,test [42] - ,test [0..4] - ,test [[True],[]] - ,test [[[1]],[[2],[3,4]],[[]]] - ,test [[True],[]] - ,test (Bin Leaf True Leaf) - ,test [Bin (Bin Leaf [1] Leaf) [2] (Bin Leaf [3] (Bin Leaf [4,5] Leaf))] - ,test [Bin (Bin Leaf [1] Leaf) [2] (Bin Leaf [3] (Bin (Bin Leaf [4,5] Leaf) [6,7] (Bin Leaf [8,9] Leaf)))] - ,test Head - ,test Tail - ,test (7,True) - ,test (Head,(7,[Tail])) - ,["End of the tests.\n"] - ] +Start = + [ test True + , test False + , test 0 + , test 123 + , test -36 + , test Head + , test Tail + , test [42] + , test [0..4] + , test [[True],[]] + , test [[[1]],[[2],[3,4]],[[]]] + , test [[True],[]] + , test (Bin Leaf True Leaf) + , test [Bin (Bin Leaf [1] Leaf) [2] (Bin Leaf [3] (Bin Leaf [4,5] Leaf))] + , test [Bin (Bin Leaf [1] Leaf) [2] (Bin Leaf [3] (Bin (Bin Leaf [4,5] Leaf) [6,7] (Bin Leaf [8,9] Leaf)))] + , test Head + , test Tail + , test (7,True) + , test (Head,(7,[Tail])) + , ["End of the tests.\n"] + ] test :: a -> [String] | serialize, == a -test a = toStrings (snd ((unS t) ser)) where - t - = write a - >>| read - >>= \b. guard (a == b) - >>| write "Oke " - <|> write "Failure " - +test a = toStrings (snd ((unS t) ser)) +where + t = write a + >>| read + >>= \b. guard (a == b) + >>| write "Oke " + <|> write "Failure " -- cgit v1.2.3