summaryrefslogtreecommitdiff
path: root/src/Data/BEncode.hs
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 /src/Data/BEncode.hs
parent49bdb7974459e2b37eb67641fd93871cc88e2fd3 (diff)
+ Document generics.
Diffstat (limited to 'src/Data/BEncode.hs')
-rw-r--r--src/Data/BEncode.hs22
1 files changed, 22 insertions, 0 deletions
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