summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Crypto/Tox.hs12
-rw-r--r--src/Data/Torrent.hs2
-rw-r--r--src/Network/BitTorrent/DHT/ContactInfo.hs6
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
84import Data.Ord 84import Data.Ord
85import Data.Serialize as S 85import Data.Serialize as S
86import Data.Semigroup
86import Data.Word 87import Data.Word
87import Foreign.Marshal.Alloc 88import Foreign.Marshal.Alloc
88import Foreign.Ptr 89import 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
163instance 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
162instance Monoid (Size a) where 169instance 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
150import Prelude 150import Prelude hiding ((<>))
151import Control.Applicative 151import Control.Applicative
152import Control.DeepSeq 152import Control.DeepSeq
153import Control.Exception 153import 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
15import Data.Maybe 15import Data.Maybe
16import Data.HashMap.Strict as HM 16import Data.HashMap.Strict as HM
17import Data.Serialize 17import Data.Serialize
18import Data.Semigroup
18import Data.Wrapper.PSQ as PSQ 19import Data.Wrapper.PSQ as PSQ
19import Data.Time.Clock.POSIX 20import Data.Time.Clock.POSIX
20import Data.ByteString (ByteString) 21import 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
194instance 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.
194instance Monoid PeerStore where 200instance Monoid PeerStore where
195 mempty = def 201 mempty = def