support all other patterns and nested patterns
[clean-tests.git] / datatype / Serialise.hs
index 524cdb3..effa82d 100644 (file)
@@ -6,36 +6,39 @@ import Data.Char
 import GHC.Generics
 
 class Serialise a where
-    serialise :: a -> [Int] -> [Int]
-    default serialise :: (Generic a, GSerialise (Rep a)) => a -> [Int] -> [Int]
-    serialise = gserialise . from
+    serialise :: a -> Int
 
-class GSerialise f where
-    gserialise :: f a -> [Int] -> [Int]
-
---Void
-instance GSerialise V1 where
-    gserialise _ = id
---Unit
-instance GSerialise U1 where
-    gserialise _ = id
---Pair
-instance (GSerialise a, GSerialise b) => GSerialise (a :*: b) where
-    gserialise (l :*: r) = gserialise l . gserialise r
---Constants, additional parameters and recursion of kind *
-instance Serialise a => GSerialise (K1 i a) where
-    gserialise (K1 a) = serialise a
---Either not supported because we don't support sumtypes in our stack machine
-instance (GSerialise a, GSerialise b) => GSerialise (a :+: b) where
-    gserialise (L1 l) = (0:) . gserialise l
-    gserialise (R1 r) = (1:) . gserialise r
---Datatype, Constructor or Selector
-instance (GSerialise a) => GSerialise (M1 i c a) where
-    gserialise (M1 l) = gserialise l
+--class serialise a where
+--    serialise :: a -> int -> [int] -> [int]
+--    default serialise :: (generic a, gserialise (rep a)) => a -> int -> [int] -> [int]
+--    serialise = gserialise . from
+--
+--class GSerialise f where
+--    gserialise :: f a -> Int -> [Int] -> [Int]
+--
+----Void
+--instance GSerialise V1 where
+--    gserialise _ _ = id
+----Unit
+--instance GSerialise U1 where
+--    gserialise _ _ = id
+----Pair
+--instance (GSerialise a, GSerialise b) => GSerialise (a :*: b) where
+--    gserialise (l :*: r) _ = gserialise l 0 . gserialise r 0
+----Constants, additional parameters and recursion of kind *
+--instance Serialise a => GSerialise (K1 i a) where
+--    gserialise (K1 a) i = serialise a i
+----Either not supported because we don't support sumtypes in our stack machine
+--instance (GSerialise a, GSerialise b) => GSerialise (a :+: b) where
+--    gserialise (L1 l) c = gserialise l (c * 2)
+--    gserialise (R1 r) c = gserialise r (c + 1)
+----Datatype, Constructor or Selector
+--instance (GSerialise a) => GSerialise (M1 i c a) where
+--    gserialise (M1 l) c = (c:) . gserialise l 0
 
 instance Serialise Int where
-    serialise i = (i:)
+    serialise i = i
 instance Serialise Bool where
-    serialise b = ((if b then 1 else 0):)
+    serialise b = if b then 1 else 0
 instance Serialise Char where
-    serialise c = (ord c:)
+    serialise c = ord c