summaryrefslogtreecommitdiff
path: root/src/Data/BEncode.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-09-29 08:03:07 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-09-29 08:03:07 +0400
commite7a93379de8af8567d052e71c6f728a4665bc102 (patch)
treee4d193336a7f6be9bc765ff39229b374a770d3f9 /src/Data/BEncode.hs
parente1810a1318da49db2e25cdcc478b41dbe938928f (diff)
Move types to separate module
Diffstat (limited to 'src/Data/BEncode.hs')
-rw-r--r--src/Data/BEncode.hs26
1 files changed, 3 insertions, 23 deletions
diff --git a/src/Data/BEncode.hs b/src/Data/BEncode.hs
index a7c766d..4d7b6c5 100644
--- a/src/Data/BEncode.hs
+++ b/src/Data/BEncode.hs
@@ -45,6 +45,8 @@
45{-# LANGUAGE FlexibleInstances #-} 45{-# LANGUAGE FlexibleInstances #-}
46{-# LANGUAGE Trustworthy #-} 46{-# LANGUAGE Trustworthy #-}
47{-# LANGUAGE CPP #-} 47{-# LANGUAGE CPP #-}
48{-# LANGUAGE BangPatterns #-}
49{-# LANGUAGE GeneralizedNewtypeDeriving #-}
48 50
49#if __GLASGOW_HASKELL__ >= 702 51#if __GLASGOW_HASKELL__ >= 702
50{-# LANGUAGE TypeOperators #-} 52{-# LANGUAGE TypeOperators #-}
@@ -137,31 +139,9 @@ import GHC.Generics
137#endif 139#endif
138 140
139import Data.BEncode.BDict as BD 141import Data.BEncode.BDict as BD
142import Data.BEncode.Types
140 143
141 144
142type BInteger = Integer
143type BString = ByteString
144type BList = [BValue]
145type BDict = BDictMap BValue
146
147-- | 'BEncode' is straightforward ADT for b-encoded values. Please
148-- note that since dictionaries are sorted, in most cases we can
149-- compare BEncoded values without serialization and vice versa.
150-- Lists is not required to be sorted through.
151--
152data BValue
153 = BInteger !BInteger -- ^ bencode integers;
154 | BString !BString -- ^ bencode strings;
155 | BList BList -- ^ list of bencode values;
156 | BDict BDict -- ^ bencode key-value dictionary.
157 deriving (Show, Read, Eq, Ord)
158
159instance NFData BValue where
160 rnf (BInteger i) = rnf i
161 rnf (BString s) = rnf s
162 rnf (BList l) = rnf l
163 rnf (BDict d) = rnf d
164
165-- | Result used in decoding operations. 145-- | Result used in decoding operations.
166type Result = Either String 146type Result = Either String
167 147