summaryrefslogtreecommitdiff
path: root/src/Crypto/Tox.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Crypto/Tox.hs')
-rw-r--r--src/Crypto/Tox.hs12
1 files changed, 8 insertions, 4 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