Use of (lawless) Group/monoid-subclasses/InverseSemigroup in view
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 18/100
調査の方向性
No files or tests are named. Start by inspecting the current Group and MonoidalMap instances in patch, then resolve whether the project should adopt InverseSemigroup or use monoid-subclasses; done means the chosen approach supports lawful Patch-related instances and has its laws and behavior verified.
索引モデルが issue の本文から書いたものです。
説明
Continuing https://github.com/Taneb/groups/issues/7#issuecomment-1006968329 in a more appropriate place:
Context: patch currently provides (but does not directly use) a Group class with lawless instance (Ord k, Group g) => Group (MonoidalMap k g). (let x = fromList [(1, y)] in x ~~ x evaluates to fromList [(1, mempty)] instead of mempty.) I'm sure that something downstream is using this class to provide efficient Patch instances or something.
Context: patch, groups, group-theory (via reexport from groups), and monoid-subclasses all provide a class that requires (<>) to be commutative. Some as a subclass of Semigroup, some as a subclass of their Group.
There are two options:
Option 1 - Create (here or elsewhere) and use an InverseSemigroup class
Since it can have lawful instance (Ord k, InverseSemigroup g) => InverseSemigroup (MonoidalMap k g):
class Semigroup g => InverseSemigroup g where
-- Laws:
-- x <> inv x <> x = x
-- inv x <> x <> inv x = x
-- inverses are unique
-- All idempotents commute
-- All idempotents have the from y = x <> inv x for some x
inv :: g -> g
(~~) :: g -> g -> g
pow :: Integral n => g -> n -> g
-- For -XDerivingVia
newtype ViaGroup g = ViaGroup g
instance Group g => InverseSemigroup (ViaGroup g)
Option 2 - Write Patch instances using monoid-subclasses instead
monoid-subclasses has class (Commutative m, LeftReductive m, RightReductive m) => Reductive m (and similar for Cancellative), and they may get you what you want. Some thoughts:
Reductiveprovides an operator(</>) :: Reductive m => m -> m -> Maybe m;Cancellativeadds two additional laws to(</>):(a <> b) </> a == Just b(a <> b) </> b == Just a
- You can't recover an inversion operation from
Cancellativealone, as you can't be certain ofisJust (mempty </> x). (Considerinstance Cancellative Natural.)- Every finite cancellative monoid is a group, but this might not be useful.
- Instance
Cancellative m => Cancellative (MonoidalMap k m)smells like it would be lawful:instance (Ord k, Commutative m) => Commutative (MonoidalMap k m) instance (Ord k, LeftReductive m) => LeftReductive (MonoidalMap k m) where stripPrefix (MonoidalMap prefix) (MonoidalMap m) = MonoidalMap <$> mergeA (traverseMissing $ \_ _ -> Nothing) (traverseMissing $ const pure) (zipWithAMatched $ \_ pf v -> stripPrefix pf v) prefix m instance (Ord k, RightReductive m) => RightReductive (MonoidalMap k m) where stripSuffix (MonoidalMap suffix) (MonoidalMap m) = MonoidalMap <$> mergeA (traverseMissing $ \_ _ -> Nothing) (traverseMissing $ const pure) (zipWithAMatched $ \_ sf v -> stripSuffix sf v) suffix m instance (Ord k, Reductive m) => Reductive (MonoidalMap k m) where MonoidalMap x </> MonoidalMap y = MonoidalMap <$> mergeA (traverseMissing $ \_ _ -> Nothing) (traverseMissing $ \_ _ -> Nothing) (zipWithAMatched $ const (</>)) x y instance (Ord k, LeftCancellative m) => LeftCancellative (MonoidalMap k m) instance (Ord k, RightCancellative m) => RightCancellative (MonoidalMap k m) instance (Ord k, CancellativeMonoid m) => Cancellative (MonoidalMap k m) - This may be enough for your uses of
patch- instead of computing the inverse of a patch, instead attempt to unapply it directly? - If you need to send data structures across a network boundary, you could do this using
[Either m m], like the free group infree-algebras. - If that's not enough, then I think you probably need to build your
patch-using stuff atop a newInverseSemigroupclass. - I'm very interested to hear what you end up doing here, and if you do make a minimal package providing
class Semigroup m => Commutative m, let me know so I can help PRmonoid-subclasses,monoidal-containers, etc.
- 主要言語
- Haskell
- スター
- 17
- フォーク
- 17
- 平均マージ
- 9時間 32分
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
reflex-frp/patch のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
reflex-frp/patch#52 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
reflex-frp/patch#44 · コメント 6 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
reflex-frp/patch#11 · リアクション 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
reflex-frp/patch#4 · コメント 15 件 ·
reflex-frp/patch の issue をすべて見る
似ている issue
-
language/en needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
kubernetes/website#57846 · コメント 2 件 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
attention: pr-welcome documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
haskell/cabal#12402 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
objectionary/phino#1600 ·
メンテナーはふだん 1 日以内に返信