1 {-# LANGUAGE DefaultSignatures, FlexibleContexts, TypeOperators #-}
8 class Serialise a where
11 --class serialise a where
12 -- serialise :: a -> int -> [int] -> [int]
13 -- default serialise :: (generic a, gserialise (rep a)) => a -> int -> [int] -> [int]
14 -- serialise = gserialise . from
16 --class GSerialise f where
17 -- gserialise :: f a -> Int -> [Int] -> [Int]
20 --instance GSerialise V1 where
21 -- gserialise _ _ = id
23 --instance GSerialise U1 where
24 -- gserialise _ _ = id
26 --instance (GSerialise a, GSerialise b) => GSerialise (a :*: b) where
27 -- gserialise (l :*: r) _ = gserialise l 0 . gserialise r 0
28 ----Constants, additional parameters and recursion of kind *
29 --instance Serialise a => GSerialise (K1 i a) where
30 -- gserialise (K1 a) i = serialise a i
31 ----Either not supported because we don't support sumtypes in our stack machine
32 --instance (GSerialise a, GSerialise b) => GSerialise (a :+: b) where
33 -- gserialise (L1 l) c = gserialise l (c * 2)
34 -- gserialise (R1 r) c = gserialise r (c + 1)
35 ----Datatype, Constructor or Selector
36 --instance (GSerialise a) => GSerialise (M1 i c a) where
37 -- gserialise (M1 l) c = (c:) . gserialise l 0
39 instance Serialise Int where
41 instance Serialise Bool where
42 serialise b = if b then 1 else 0
43 instance Serialise Char where