diff options
Diffstat (limited to 'src/Data/BEncode.hs')
-rw-r--r-- | src/Data/BEncode.hs | 22 |
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 | -- | ||
161 | class BEncodable a where | 183 | class 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 |