diff options
Diffstat (limited to 'src/Crypto/Tox.hs')
-rw-r--r-- | src/Crypto/Tox.hs | 12 |
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 |
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 | ||