From ad6235f30d9defe8b0be6e0fb5b873e5fc14d067 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Mon, 30 Sep 2013 05:26:09 +0400 Subject: Introduce Assoc datatype --- src/Data/BEncode.hs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Data/BEncode.hs b/src/Data/BEncode.hs index f12d116..ebeed6e 100644 --- a/src/Data/BEncode.hs +++ b/src/Data/BEncode.hs @@ -648,14 +648,13 @@ fromDict _ _ = decodingError (show (typeOf inst)) -- > ] -- > ... -- -type Assoc = Maybe BPair - -type BPair = (BKey, BValue) +data Assoc = Some BKey BValue + | None -- TODO better name -- | Make required key value pair. (.=!) :: BEncode a => BKey -> a -> Assoc -k .=! v = Just (k, toBEncode v) +k .=! v = Some k (toBEncode v) {-# INLINE (.=!) #-} infix 6 .=! @@ -664,15 +663,15 @@ infix 6 .=! -- appear in resulting bencoded dictionary. -- (.=?) :: BEncode a => BKey -> Maybe a -> Assoc -_ .=? Nothing = Nothing -k .=? Just v = Just (k, toBEncode v) +_ .=? Nothing = None +k .=? Just v = Some k (toBEncode v) {-# INLINE (.=?) #-} infix 6 .=? (.:) :: Assoc -> BDict -> BDict -Nothing .: d = d -Just (k, v) .: d = Cons k v d +None .: d = d +Some k v .: d = Cons k v d {-# INLINE (.:) #-} infixr 5 .: -- cgit v1.2.3