From 2abd00f548b7b9565b2a6bc1bed793d2a6f8c9cd Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Sun, 1 Dec 2013 17:57:59 +0400 Subject: Add functor instances to Block and Piece --- src/Data/Torrent/Block.hs | 11 +++++++---- src/Data/Torrent/Piece.hs | 7 ++++--- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Data/Torrent/Block.hs b/src/Data/Torrent/Block.hs index 37889a7a..1e0a929d 100644 --- a/src/Data/Torrent/Block.hs +++ b/src/Data/Torrent/Block.hs @@ -7,9 +7,11 @@ -- -- Blocks are used to transfer pieces. -- -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} module Data.Torrent.Block ( -- * Piece attributes PieceIx @@ -38,6 +40,7 @@ import qualified Data.ByteString.Lazy as Lazy import Data.Char import Data.List as L import Data.Serialize as S +import Data.Typeable import Text.PrettyPrint import Text.PrettyPrint.Class @@ -95,7 +98,7 @@ data BlockIx = BlockIx { -- | Block size starting from offset. , ixLength :: {-# UNPACK #-} !BlockSize - } deriving (Show, Eq) + } deriving (Show, Eq, Typeable) $(deriveJSON (L.map toLower . L.dropWhile isLower) ''BlockIx) @@ -148,7 +151,7 @@ data Block payload = Block { -- | Payload bytes. , blkData :: !payload - } deriving (Show, Eq) + } deriving (Show, Eq, Functor, Typeable) -- | Payload is ommitted. instance Pretty (Block Lazy.ByteString) where diff --git a/src/Data/Torrent/Piece.hs b/src/Data/Torrent/Piece.hs index 7eb4e3d5..c6223348 100644 --- a/src/Data/Torrent/Piece.hs +++ b/src/Data/Torrent/Piece.hs @@ -7,8 +7,9 @@ -- -- Pieces are used to validate torrent content. -- -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} module Data.Torrent.Piece ( -- * Piece attributes @@ -115,7 +116,7 @@ data Piece a = Piece -- | Payload. , pieceData :: !a - } deriving (Show, Read, Eq, Typeable) + } deriving (Show, Read, Eq, Functor, Typeable) $(deriveJSON (L.map toLower . L.dropWhile isLower) ''Piece) -- cgit v1.2.3