Giter Site home page Giter Site logo

Comments (6)

andreasabel avatar andreasabel commented on September 21, 2024 1

Ok, thanks @conal, then we do not take further action here.

from agda.

jespercockx avatar jespercockx commented on September 21, 2024

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 use Q to choose the instance rather than just X.

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.

jkopanski avatar jkopanski commented on September 21, 2024
  • 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.

conal avatar conal commented on September 21, 2024

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.

jespercockx avatar jespercockx commented on September 21, 2024

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.

conal avatar conal commented on September 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.