From e7a93379de8af8567d052e71c6f728a4665bc102 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Sun, 29 Sep 2013 08:03:07 +0400 Subject: Move types to separate module --- src/Data/BEncode.hs | 26 +++----------------------- src/Data/BEncode/Types.hs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 src/Data/BEncode/Types.hs (limited to 'src') 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 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE Trustworthy #-} {-# LANGUAGE CPP #-} +{-# LANGUAGE BangPatterns #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE TypeOperators #-} @@ -137,31 +139,9 @@ import GHC.Generics #endif import Data.BEncode.BDict as BD +import Data.BEncode.Types -type BInteger = Integer -type BString = ByteString -type BList = [BValue] -type BDict = BDictMap BValue - --- | 'BEncode' is straightforward ADT for b-encoded values. Please --- note that since dictionaries are sorted, in most cases we can --- compare BEncoded values without serialization and vice versa. --- Lists is not required to be sorted through. --- -data BValue - = BInteger !BInteger -- ^ bencode integers; - | BString !BString -- ^ bencode strings; - | BList BList -- ^ list of bencode values; - | BDict BDict -- ^ bencode key-value dictionary. - deriving (Show, Read, Eq, Ord) - -instance NFData BValue where - rnf (BInteger i) = rnf i - rnf (BString s) = rnf s - rnf (BList l) = rnf l - rnf (BDict d) = rnf d - -- | Result used in decoding operations. type Result = Either String diff --git a/src/Data/BEncode/Types.hs b/src/Data/BEncode/Types.hs new file mode 100644 index 0000000..e505249 --- /dev/null +++ b/src/Data/BEncode/Types.hs @@ -0,0 +1,45 @@ +-- | +-- Copyright : (c) Sam Truzjan 2013 +-- License : BSD3 +-- Maintainer : pxqr.sta@gmail.com +-- Stability : stable +-- Portability : portable +-- +-- Types for working with bencode data. +-- +module Data.BEncode.Types + ( BInteger + , BString + , BList + , BDict + , BValue (..) + ) where + +import Control.DeepSeq +import Data.ByteString + +import Data.BEncode.BDict + + +type BInteger = Integer +type BString = ByteString +type BList = [BValue] +type BDict = BDictMap BValue + +-- | 'BEncode' is straightforward ADT for b-encoded values. Please +-- note that since dictionaries are sorted, in most cases we can +-- compare BEncoded values without serialization and vice versa. +-- Lists is not required to be sorted through. +-- +data BValue + = BInteger !BInteger -- ^ bencode integers; + | BString !BString -- ^ bencode strings; + | BList BList -- ^ list of bencode values; + | BDict BDict -- ^ bencode key-value dictionary. + deriving (Show, Read, Eq, Ord) + +instance NFData BValue where + rnf (BInteger i) = rnf i + rnf (BString s) = rnf s + rnf (BList l) = rnf l + rnf (BDict d) = rnf d -- cgit v1.2.3