Comments (10)
If you can provide more information, I'm happy to see if I can find a nice way to address your problem.
from coq-ext-lib.
The reason is that the index of the data structure (T
) does not uniquely determine the Monoid
. You could have + and 0, or * and 1, etc. We could go the Haskell route and wrap things, but I chose not to go that way initially because the wrapping incurs a performance cost.
from coq-ext-lib.
But unlike Haskell Coq allows multiple typeclass instances for a type.
I do not have statistics on this but I suspect that in most practical uses there will be one monoid per type and using typeclass will make it much easier to work with it. In rare cases when there are multiple monoids per type they will have to specify which instance to use implicitly.
from coq-ext-lib.
Is this is the intended way of doing monoid-related things(suppose I need Monoid (list ..)
instance for WriterMonad
:
Existing Class Monoid.
Existing Instance Monoid_list_app.
?
from coq-ext-lib.
My understanding is that Existing Class
is "infectious", so if you use it, then everyone who depends on you is also forced to use it. If this is the recommended style, then ExtLib should change Monoid
into a Class
and users should specify instances manually when there are multiple of them.
An alternative is to use Local
notations for certain things, e.g.
Local Notation "a ++ b" := (Monoid_list_app.(monoid_plus) a b) ...
from coq-ext-lib.
I'm not writing a lib, I need it only for a certain class of definitions... What is a Local
notations thing? How can it help me to write MonadWriter
instances? Maybe you know a better way to do this?
from coq-ext-lib.
It would be very nice.
Basically, the problem is that I got an error while trying to use tell
(from MonadWriter
) saying:
Error: Cannot infer the implicit parameter MT of tell whose type is "Monoid (list Z)".
In this definition:
Definition test : cM unit := tell (cons 1%Z nil).
Where cM
is a custom monad that has MonadWriter
instance.
If I understood this problem correctly, it all comes down to the fact, that Monoid
isn't a typecleass, so resolver don't even know about it and it's instances.
If I'm not mistaken there must be some common way to do this, because every MonadWriter
instance needs a log that is a Monoid
instance.
So, what is the best solution for this?
from coq-ext-lib.
I have a short example here for you to play with
https://gist.github.com/p3rsik/5c57b38c6f37734bece81b675dd0b238
from coq-ext-lib.
@gmalecha I am also curious to see if there is a better solution.
from coq-ext-lib.
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 Monoid
a type class and wrap things the way that Haskell does, i.e. you might not have an instance for Monoid nat
but rather for something like:
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.
from coq-ext-lib.
Related Issues (20)
- The EqvWF_Build instance messes up with typeclass resolution
- Please create a tag for the upcoming release of Coq 8.13 HOT 2
- Please create a tag for the upcoming release of Coq 8.14 HOT 2
- Right Idenity in MonadLaw HOT 4
- Duplicate Monad List instances HOT 3
- `Set Typeclass Strict Resolution`
- `Monad list` instances will cause template-polymorphism problems
- Please pick the version you prefer for Coq 8.15 in Coq Platform 2022.02 HOT 3
- Please pick the version you prefer for Coq 8.16 in Coq Platform 2022.09 HOT 2
- can't install package coq-ext-lib for coq 8.12 HOT 3
- what is the most stable version for coq 8.12, 0.11.7 or dev? is dev stable? HOT 2
- Please pick the version you prefer for Coq 8.17 in Coq Platform 2023.03 HOT 2
- Please pick the version you prefer for Coq 8.18 in Coq Platform 2023.10
- Metadata problem with release 0.12.1 on opam HOT 2
- rwHyps stops on first recursive equality
- Please pick the version you prefer for Coq 8.19 in Coq Platform 2024.01 HOT 2
- build problem HOT 2
- stdlibpp
- Add the let* monadic notation HOT 3
- notation conflict HOT 24
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coq-ext-lib.