diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Crypto/Tox.hs | 12 | ||||
-rw-r--r-- | src/Data/Torrent.hs | 2 | ||||
-rw-r--r-- | src/Network/BitTorrent/DHT/ContactInfo.hs | 6 |
3 files changed, 15 insertions, 5 deletions
diff --git a/src/Crypto/Tox.hs b/src/Crypto/Tox.hs index d1992967..a1741a1f 100644 --- a/src/Crypto/Tox.hs +++ b/src/Crypto/Tox.hs | |||
@@ -83,6 +83,7 @@ import GHC.Exts (Constraint) | |||
83 | #endif | 83 | #endif |
84 | import Data.Ord | 84 | import Data.Ord |
85 | import Data.Serialize as S | 85 | import Data.Serialize as S |
86 | import Data.Semigroup | ||
86 | import Data.Word | 87 | import Data.Word |
87 | import Foreign.Marshal.Alloc | 88 | import Foreign.Marshal.Alloc |
88 | import Foreign.Ptr | 89 | import Foreign.Ptr |
@@ -159,11 +160,14 @@ instance Contravariant Size where | |||
159 | ConstSize n -> ConstSize n | 160 | ConstSize n -> ConstSize n |
160 | VarSize g -> VarSize (\x -> g (f x)) | 161 | VarSize g -> VarSize (\x -> g (f x)) |
161 | 162 | ||
163 | instance Semigroup (Size a) where | ||
164 | ConstSize x <> ConstSize y = ConstSize (x + y) | ||
165 | VarSize f <> ConstSize y = VarSize $ \x -> f x + y | ||
166 | ConstSize x <> VarSize g = VarSize $ \y -> x + g y | ||
167 | VarSize f <> VarSize g = VarSize $ \x -> f x + g x | ||
168 | |||
162 | instance Monoid (Size a) where | 169 | instance Monoid (Size a) where |
163 | ConstSize x `mappend` ConstSize y = ConstSize (x + y) | 170 | mappend = (<>) |
164 | VarSize f `mappend` ConstSize y = VarSize $ \x -> f x + y | ||
165 | ConstSize x `mappend` VarSize g = VarSize $ \y -> x + g y | ||
166 | VarSize f `mappend` VarSize g = VarSize $ \x -> f x + g x | ||
167 | mempty = ConstSize 0 | 171 | mempty = ConstSize 0 |
168 | 172 | ||
169 | 173 | ||
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs index 4af583ed..dbe248eb 100644 --- a/src/Data/Torrent.hs +++ b/src/Data/Torrent.hs | |||
@@ -147,7 +147,7 @@ module Data.Torrent | |||
147 | , renderURN | 147 | , renderURN |
148 | ) where | 148 | ) where |
149 | 149 | ||
150 | import Prelude | 150 | import Prelude hiding ((<>)) |
151 | import Control.Applicative | 151 | import Control.Applicative |
152 | import Control.DeepSeq | 152 | import Control.DeepSeq |
153 | import Control.Exception | 153 | import Control.Exception |
diff --git a/src/Network/BitTorrent/DHT/ContactInfo.hs b/src/Network/BitTorrent/DHT/ContactInfo.hs index dfc93ed7..ed38caf7 100644 --- a/src/Network/BitTorrent/DHT/ContactInfo.hs +++ b/src/Network/BitTorrent/DHT/ContactInfo.hs | |||
@@ -15,6 +15,7 @@ import Data.List as L | |||
15 | import Data.Maybe | 15 | import Data.Maybe |
16 | import Data.HashMap.Strict as HM | 16 | import Data.HashMap.Strict as HM |
17 | import Data.Serialize | 17 | import Data.Serialize |
18 | import Data.Semigroup | ||
18 | import Data.Wrapper.PSQ as PSQ | 19 | import Data.Wrapper.PSQ as PSQ |
19 | import Data.Time.Clock.POSIX | 20 | import Data.Time.Clock.POSIX |
20 | import Data.ByteString (ByteString) | 21 | import Data.ByteString (ByteString) |
@@ -190,6 +191,11 @@ instance Default (PeerStore) where | |||
190 | def = PeerStore HM.empty | 191 | def = PeerStore HM.empty |
191 | {-# INLINE def #-} | 192 | {-# INLINE def #-} |
192 | 193 | ||
194 | instance Semigroup PeerStore where | ||
195 | PeerStore a <> PeerStore b = | ||
196 | PeerStore (HM.unionWith swarmInsert a b) | ||
197 | {-# INLINE (<>) #-} | ||
198 | |||
193 | -- | Monoid under union operation. | 199 | -- | Monoid under union operation. |
194 | instance Monoid PeerStore where | 200 | instance Monoid PeerStore where |
195 | mempty = def | 201 | mempty = def |