-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Why is Monoid a record rather than a Class #82
Comments
The reason is that the index of the data structure ( |
But unlike Haskell Coq allows multiple typeclass instances for a type. |
Is this is the intended way of doing monoid-related things(suppose I need
? |
My understanding is that An alternative is to use Local Notation "a ++ b" := (Monoid_list_app.(monoid_plus) a b) ... |
I'm not writing a lib, I need it only for a certain class of definitions... What is a |
If you can provide more information, I'm happy to see if I can find a nice way to address your problem. |
It would be very nice.
In this definition:
Where |
I have a short example here for you to play with |
@gmalecha I am also curious to see if there is a better solution. |
Sorry for not responding earlier. The hacky way to solve this problem is something like: Local Notation tell := (tell (M:=Monoid_list_app _)) You can also convert this into a definition like: Definition tellN (n : list Z) : Writer nat unit :=
tell (M:=Monoid_list_app ...) n. A better solution, however, would be ideal. Perhaps that is to make Record Plus : Set := mkPlus
{ unplus : nat }.
Coercion mkPlus : nat >-> Plus.
Instance Monoid_Plus : Monoid Plus :=
{ monoid_plus a b := mkPlus (Nat.add a.(unplus) b.(unplus))
; monoid_unit := mkPlus 0 }.
... MonadWriter Plus T. This is a lot of boilerplate though. |
Monoids in
coq-ext-lib
are defined as follow:coq-ext-lib/theories/Structures/Monoid.v
Lines 11 to 14 in ee71d14
Is there a special reason that the definition is a
Record
rather than aClass
? I know that, under the hood, they are the same thing, but if my understanding is correct, you will not be able to declare a data structure as aninstance
of aMonoid
unless you useExisting Class Monoid
(why cannot be found incoq-ext-lib
).The text was updated successfully, but these errors were encountered: