Comments (6)
Ok, thanks @conal, then we do not take further action here.
from agda.
I think the problem here is that Agda's automatic insertion of implicit arguments is making the instance search go awry. In particular, if you make the x
argument to q
explicit then the example passes:
record Foo (X : Set) : Set₁ where
field
Q : X → Set
q : (x : X) → Q x
open Foo ⦃ … ⦄
module Test (A : Set) ⦃ FooA : Foo A ⦄ (B : Set) ⦃ FooB : Foo B ⦄ where
works : (y : B) → Q y
works = q
So the problem is that instance search does not get the task of searching for an instance inst
where the type of q {{inst}}
is {x : B} → Q {{inst}} x
(which it could solve) but instead it it has to search for an instance inst
where q {{inst}} {y}
has type Q {{inst}} y
. In the latter case there is no trace of the type A
which it could use to choose the instance of type Foo B
over the one of type Foo A
.
Possible workarounds could be:
- Making the argument
{x : X}
explicit. - Wrapping the type of
q
in a box that prevents Agda from eagerly inserting the implicit argument. - Making
Q
into an additional parameter of the type class (so instance search can useQ
to choose the instance rather than justX
.
Would any of these options be acceptable to you? The goal of this change was to make instance search more predictable and performant, but this will inevitably lead to some cases like this where Agda has a harder time choosing the correct instance.
from agda.
- Wrapping the type of
q
in a box that prevents Agda from eagerly inserting the implicit argument.
Would you be so kind and show what this would look like? I don't really understand this.
from agda.
Thank you for the tips, @jespercockx! Of your workaround suggestions, the first and third would be terribly awkward in practice, and the second I don’t understand.
from agda.
What I meant with the second point is to define a type like
data Box (A : Set) : Set where
[_] : A -> Box A
and change the type of q
from {x : X} → Q x
to Box ({x : X} → Q x)
. But that's probably going to be pretty awkward to work with too.
If none of the workarounds here are acceptable, I'm not sure what would be the best solution here. There are just too many different use cases for instance search, and every time we make a change that makes things better (more predictable, more efficient) for one use case this inevitably makes things worse for another use case elsewhere.
(One other workaround which you probably won't like is to use tactic arguments with a custom tactic instead of instance arguments. Here is an example of a little tactic that I wrote that relies on instance search but removes the uniqueness constraint: https://github.com/jespercockx/scope/blob/master/src/Utils/Tactics.agda#L31-L55, perhaps a similar tactic could be adapted to your use case.)
from agda.
Thanks again, @jespercockx! I think @jkopanski has found a strategy that we can live with. Theorems are still pretty (my top priority), and proofs are only mildly more verbose.
from agda.
Related Issues (20)
- Range printed twice for "Parse error" HOT 1
- Code only reachable from display forms not serialised in Agda 2.7.0 HOT 21
- Parse errors are communicated as `Exception` duplicating their range.
- Some warnings aren't yet covered by our testsuite
- Unexpected hidden argument in nested records/modules HOT 6
- Regression: emptiness check fails when erased constructors are involved HOT 8
- `--exact-split` is not default in 2.7.0, contrary to claims
- Instance missing when abstracting over an incomplete type HOT 3
- Instances found by instance search are inlined HOT 2
- Performance regression caused by making `--save-metas` the default HOT 9
- Both stack and cabal fail to install Agda HOT 5
- Deprecate idiom brackets? HOT 4
- Verbosity options are not picked up from the main module when this module is deserialized unchanged
- Compiled `--erased-cubical` program produces non-deterministic value HOT 3
- Extend the emptiness check to all pattern records? HOT 7
- [bug?] `WARNING_ON_USAGE` in parameterised module/record fails to fire after module instantiation HOT 2
- Unguarded eta records can make Agda loop HOT 1
- Delete or reproduce a check for unsolved metas in Backend.hs HOT 1
- Internal error using Mimer in where block HOT 3
- Instance overlaps with all other instances HOT 6
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 agda.