From 5b90e7d827aa7527ab97fe24f5ae2affcfe3a542 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Tue, 1 Sep 2015 14:22:45 +0200 Subject: [PATCH] works except untyped trees and lists out of the box --- a1/mart/skeleton1.icl | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/a1/mart/skeleton1.icl b/a1/mart/skeleton1.icl index dd17d73..128974d 100644 --- a/a1/mart/skeleton1.icl +++ b/a1/mart/skeleton1.icl @@ -105,8 +105,27 @@ listToGen [x:xs] = RIGHT (PAIR x xs) //2.3. EITHER (PAIR 1 (PAIR 2 3)) UNIT // Nope, it will leave the xs to be so it will be: EITHER (PAIR 1 [2,3]) -//2.4. Nope, not possible since they are basic types and they can't be -// converted to UNIT, EITHER or PAIR. +//2.4. Yes, for Int and Char it works fine but for list and tuples you'll run +// into problems. +//class toGen a :: a -> GenG a +// +//:: IntG :== EITHER UNIT (PAIR UNIT Int) +//:: CharG :== EITHER UNIT (PAIR UNIT Char) +//:: ListG a :== EITHER UNIT (PAIR a [a]) +//:: GenG a :== EITHER IntG (EITHER CharG (ListG a)) +// +//instance toGen Int where +// toGen 0 = LEFT (LEFT UNIT) +// toGen x = LEFT (RIGHT (PAIR UNIT (x-1))) +// +//instance toGen Char where +// toGen x +// | fromChar x == 0 = RIGHT (LEFT (LEFT UNIT)) +// | otherwise = RIGHT (LEFT (RIGHT (PAIR UNIT (x-(toChar 1))))) +// +//instance toGen [] where +// toGen [] = RIGHT (RIGHT (LEFT UNIT)) +// toGen [x:xs] = RIGHT (RIGHT (RIGHT (PAIR (x xs)))) //3. Ordering via generic representation //3.1 @@ -151,5 +170,10 @@ treeToGen (Bin x xr xl) = RIGHT (PAIR x (PAIR xr xl)) Start = [Red >< Yellow, Blue >< Yellow, Blue >< Blue, (Bin 1 Tip Tip) >< Tip, + [1, 2] >< [2, 3], + [1, 2] >< [1, 2], + [1, 3] >< [1, 2], +// [] >< [], +// Tip >< Tip, (Bin 1 Tip Tip) >< (Bin 1 Tip Tip), Tip >< (Bin 1 Tip Tip) ] -- 2.20.1