summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-08-26 22:21:18 +0400
committerSam T <pxqr.sta@gmail.com>2013-08-26 22:21:18 +0400
commitbd3bbbf8d778b79b0eabba04c7b9ae83a643ca65 (patch)
treeca5ee6c78a3b0b1bbd2116b03b4754093a4b7600
parent49bdb7974459e2b37eb67641fd93871cc88e2fd3 (diff)
+ Document generics.
-rw-r--r--TODO.org2
-rw-r--r--src/Data/BEncode.hs22
2 files changed, 23 insertions, 1 deletions
diff --git a/TODO.org b/TODO.org
index 5f18148..eed927c 100644
--- a/TODO.org
+++ b/TODO.org
@@ -3,7 +3,7 @@
3* DONE lens compatible selectors renaming 3* DONE lens compatible selectors renaming
4* DONE benchmarks for generic decode 4* DONE benchmarks for generic decode
5* DONE documentation 5* DONE documentation
6* TODO document generics 6* DONE document generics
7* TODO v0.2.0.0 (reason: dictAssoc is hidded now) 7* TODO v0.2.0.0 (reason: dictAssoc is hidded now)
8* TODO use HashMap 8* TODO use HashMap
9* TODO CPS Result 9* TODO CPS Result
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
158 158
159-- | This class is used to define new datatypes that could be easily 159-- | This class is used to define new datatypes that could be easily
160-- serialized using bencode format. 160-- serialized using bencode format.
161--
162-- By default 'BEncodable' have a generic implementation; suppose
163-- the following datatype:
164--
165-- > data List a = Cons { _head :: a
166-- > , __tail :: (List a) }
167-- > | Nil
168-- > deriving Generic
169--
170-- If we don't need to obey any particular specification or
171-- standard, the default instance could be derived automatically
172-- from the 'Generic' instance:
173--
174-- > instance BEncodable a => BEncodable (List a)
175--
176-- Example of derived 'toBEncode' result:
177--
178-- > > toBEncode (Cons 123 $ Cons 1 Nil)
179-- > BDict (fromList [("head",BInteger 123),("tail",BList [])])
180--
181-- Note that '_' prefixes are omitted.
182--
161class BEncodable a where 183class BEncodable a where
162 -- | See an example of implementation here 'Assoc' 184 -- | See an example of implementation here 'Assoc'
163 toBEncode :: a -> BEncode 185 toBEncode :: a -> BEncode