Skip to content

Commit

Permalink
Merge pull request #51 from BlackCapCoder/master
Browse files Browse the repository at this point in the history
added stimes implementations
  • Loading branch information
byorgey authored Nov 16, 2021
2 parents e48bb70 + 5b2d4e5 commit ad82ce5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Data/Monoid/Cut.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ instance Semigroup m => Semigroup (Cut m) where
(m1 :||: m2) <> (Uncut m2') = m1 :||: m2 <> m2'
(m11 :||: _) <> (_ :||: m22) = m11 :||: m22

stimes n (Uncut m) = Uncut (stimes n m)
stimes n (m ) = m

instance (Semigroup m, Monoid m) => Monoid (Cut m) where
mempty = Uncut mempty
mappend = (<>)
Expand Down
7 changes: 7 additions & 0 deletions src/Data/Monoid/Deletable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ instance Semigroup m => Semigroup (Deletable m) where
| l1 < r2 = Deletable (r1 + r2 - l1) m2 l2
| otherwise = Deletable r1 m1 (l2 + l1 - r2)

stimes n (Deletable r m l)
| r == l = Deletable r (stimes n m) l
| l < r = Deletable (i*(r-l) + l) m l
| otherwise = Deletable r m (i*(l-r) + r)
where
i = fromIntegral n :: Int

instance (Semigroup m, Monoid m) => Monoid (Deletable m) where
mempty = Deletable 0 mempty 0
mappend = (<>)
Expand Down
3 changes: 3 additions & 0 deletions src/Data/Monoid/Recommend.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ instance Semigroup a => Semigroup (Recommend a) where
Commit a <> Recommend _ = Commit a
Commit a <> Commit b = Commit (a <> b)

stimes n (Recommend m) = Recommend (stimes n m)
stimes n (Commit m) = Commit (stimes n m)

instance (Semigroup a, Monoid a) => Monoid (Recommend a) where
mappend = (<>)
mempty = Recommend mempty
4 changes: 4 additions & 0 deletions src/Data/Monoid/Split.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ instance Semigroup m => Semigroup (Split m) where
(m1 :| m2) <> (M m2') = m1 :| m2 <> m2'
(m11 :| m12) <> (m21 :| m22) = m11 <> m12 <> m21 :| m22

stimes n (M m ) = M (stimes n m)
stimes 1 (m ) = m
stimes n (m1 :| m2) = m1 <> stimes (pred n) (m2 <> m1) :| m2

instance (Semigroup m, Monoid m) => Monoid (Split m) where
mempty = M mempty
mappend = (<>)
Expand Down

0 comments on commit ad82ce5

Please sign in to comment.