\r
//2.3. EITHER (PAIR 1 (PAIR 2 3)) UNIT \r
// Nope, it will leave the xs to be so it will be: EITHER (PAIR 1 [2,3])\r
-//2.4. Nope, not possible since they are basic types and they can't be\r
-// converted to UNIT, EITHER or PAIR.\r
+//2.4. Yes, for Int and Char it works fine but for list and tuples you'll run\r
+// into problems.\r
+//class toGen a :: a -> GenG a\r
+//\r
+//:: IntG :== EITHER UNIT (PAIR UNIT Int)\r
+//:: CharG :== EITHER UNIT (PAIR UNIT Char)\r
+//:: ListG a :== EITHER UNIT (PAIR a [a])\r
+//:: GenG a :== EITHER IntG (EITHER CharG (ListG a))\r
+//\r
+//instance toGen Int where\r
+// toGen 0 = LEFT (LEFT UNIT)\r
+// toGen x = LEFT (RIGHT (PAIR UNIT (x-1)))\r
+//\r
+//instance toGen Char where\r
+// toGen x\r
+// | fromChar x == 0 = RIGHT (LEFT (LEFT UNIT))\r
+// | otherwise = RIGHT (LEFT (RIGHT (PAIR UNIT (x-(toChar 1)))))\r
+//\r
+//instance toGen [] where\r
+// toGen [] = RIGHT (RIGHT (LEFT UNIT))\r
+// toGen [x:xs] = RIGHT (RIGHT (RIGHT (PAIR (x xs))))\r
\r
//3. Ordering via generic representation\r
//3.1\r
\r
Start = [Red >< Yellow, Blue >< Yellow, Blue >< Blue,\r
(Bin 1 Tip Tip) >< Tip,\r
+ [1, 2] >< [2, 3],\r
+ [1, 2] >< [1, 2],\r
+ [1, 3] >< [1, 2],\r
+// [] >< [],\r
+// Tip >< Tip,\r
(Bin 1 Tip Tip) >< (Bin 1 Tip Tip),\r
Tip >< (Bin 1 Tip Tip) ]\r