-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use of (lawless) Group/monoid-subclasses/InverseSemigroup in view #37
Comments
A bit off-topic, but @endgame you might be interested in https://github.com/obsidiansystems/finite-support-normal-form/blob/main/src/Data/Map/Total/FSNF.hs . It's a bit heavyweight --- using a type family like that is definitely a smell --- but by making it impossible to have a Note that it requires https://github.com/mstksg/nonempty-containers/pull/13/files to build. |
That is indeed heavyweight, but I think that if you want to ban instance (Ord k, MonoidNull m) => Semigroup (Normalized (MonoidalMap k v))
instance (Ord k, MonoidNull m) => Monoid (Normalized (MonoidalMap k v))
instance (Ord k, MonoidNull g, Group g) => Group (Normalized (MonoidalMap k g)) Here, "normalisation" means "there are no |
Thinking about this again: would putting Though you lose |
Since nothing in |
The main downstream thing I'm aware of is |
@endgame Not sure if you're still interested in this topic (as the last comment was from some time ago), but I did recently create a similar type to the one you describe:
Features:
I haven't released it to hackage yet, as I'm still reviewing the API. Not sure if you're interested in taking a look, but I'd be very interested to hear any feedback that you might have! All the best |
Very cool, thanks for pinging me. I think that in many cases I want a non-total map with a valid grouplike structure, so I think eventually I might write a package that provides I probably won't have time to go over it thoroughly, but it's good that you're exploring this design space. You might also want to look at packages |
No worries. Thanks for looking!
Definitely -- these are two packages whose design I'm studying very carefully.
I'm not sure it's possible to build a lawful
Sure, thanks for looking! I'll try to avoid creating further noise in this thread. 😄 |
Continuing Taneb/groups#7 (comment) in a more appropriate place:
Context:
patch
currently provides (but does not directly use) aGroup
class with lawlessinstance (Ord k, Group g) => Group (MonoidalMap k g)
. (let x = fromList [(1, y)] in x ~~ x
evaluates tofromList [(1, mempty)]
instead ofmempty
.) I'm sure that something downstream is using this class to provide efficientPatch
instances or something.Context:
patch
,groups
,group-theory
(via reexport fromgroups
), andmonoid-subclasses
all provide a class that requires(<>)
to be commutative. Some as a subclass ofSemigroup
, some as a subclass of theirGroup
.There are two options:
Option 1 - Create (here or elsewhere) and use an
InverseSemigroup
classSince it can have lawful
instance (Ord k, InverseSemigroup g) => InverseSemigroup (MonoidalMap k g)
:Option 2 - Write
Patch
instances usingmonoid-subclasses
insteadmonoid-subclasses
hasclass (Commutative m, LeftReductive m, RightReductive m) => Reductive m
(and similar forCancellative
), and they may get you what you want. Some thoughts:Reductive
provides an operator(</>) :: Reductive m => m -> m -> Maybe m
;Cancellative
adds two additional laws to(</>)
:(a <> b) </> a == Just b
(a <> b) </> b == Just a
Cancellative
alone, as you can't be certain ofisJust (mempty </> x)
. (Considerinstance Cancellative Natural
.)Cancellative m => Cancellative (MonoidalMap k m)
smells like it would be lawful:patch
- instead of computing the inverse of a patch, instead attempt to unapply it directly?[Either m m]
, like the free group infree-algebras
.patch
-using stuff atop a newInverseSemigroup
class.class Semigroup m => Commutative m
, let me know so I can help PRmonoid-subclasses
,monoidal-containers
, etc.The text was updated successfully, but these errors were encountered: