From bd3bbbf8d778b79b0eabba04c7b9ae83a643ca65 Mon Sep 17 00:00:00 2001 From: Sam T Date: Mon, 26 Aug 2013 22:21:18 +0400 Subject: + Document generics. --- src/Data/BEncode.hs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/Data/BEncode.hs') diff --git a/src/Data/BEncode.hs b/src/Data/BEncode.hs index f41e4b8..d18d787 100644 --- a/src/Data/BEncode.hs +++ b/src/Data/BEncode.hs @@ -158,6 +158,28 @@ type Result = Either String -- | This class is used to define new datatypes that could be easily -- serialized using bencode format. +-- +-- By default 'BEncodable' have a generic implementation; suppose +-- the following datatype: +-- +-- > data List a = Cons { _head :: a +-- > , __tail :: (List a) } +-- > | Nil +-- > deriving Generic +-- +-- If we don't need to obey any particular specification or +-- standard, the default instance could be derived automatically +-- from the 'Generic' instance: +-- +-- > instance BEncodable a => BEncodable (List a) +-- +-- Example of derived 'toBEncode' result: +-- +-- > > toBEncode (Cons 123 $ Cons 1 Nil) +-- > BDict (fromList [("head",BInteger 123),("tail",BList [])]) +-- +-- Note that '_' prefixes are omitted. +-- class BEncodable a where -- | See an example of implementation here 'Assoc' toBEncode :: a -> BEncode -- cgit v1.2.3