Giter Site home page Giter Site logo

Comments (3)

andreasabel avatar andreasabel commented on June 17, 2024

It works if you make parameter B in associative explicit and put it at the beginning.

record Monad (M : Set  Set) : Set₁ where
  field
    bind : {A B : Set}  (A  M B)  M A  M B

    associative :  (B : Set) {A C : Set}  {f : A  M B}  {g : B  M C}  bind g ∘ bind f ≡ bind (bind g ∘ f)

M : Set  Set  Set
M R A = (A  R)  R

bind : {R A B : Set}  (A  M R B)  M R A  M R B
bind f a = λ cont  a (λ a'  f a' cont)

associative :  {R} B {A C}  {f : A  M R B}  {g : B  M R C}  bind g ∘ bind f ≡ bind (bind g ∘ f)
associative B = refl

contMonad : (R : Set)  Monad (M R)
contMonad R = record { bind = bind; associative = associative }

The problem in the OP is that Agda eagerly inserts implicit arguments, but then it cannot recover the solutions for B, g and f because they are not unique in higher-order unification. The cure is to make the first parameter explicit when this happens.

from agda.

andreasabel avatar andreasabel commented on June 17, 2024

Something for consideration is whether we should make the record-from-module syntax behave more akin to the user expectation, so don't just resolve it to a record expression before type-checking, but have a more direct mechanism that short-cuts the insertion of implicit arguments.

from agda.

ibbem avatar ibbem commented on June 17, 2024

OK, Thanks. I think that I understand the problem now.

I'm quite new to Agda but I intuitively expected that record { associative = associative } would only eagerly apply as many implicit arguments to g until it has the same number (or less) implicit arguments left as f. Then the rest of the type could be unified. As far as I understand this would have the same effect as stopping eager application of implicit arguments by adding a dummy explicit argument as the first parameter, like in this example:

record Monad (M : Set -> Set) : Set₁ where
  field
    bind : {A B : Set}  (A  M B)  M A  M B

    associative : (Z : Set) -> {A B C : Set}  {f : A  M B}  {g : B  M C}  bind g ∘ bind f ≡ bind (bind g ∘ f)

M : Set -> Set -> Set
M R A = (A -> R) -> R

bind : {R A B : Set}  (A  M R B)  M R A  M R B
bind f a = λ cont -> a (λ a' -> f a' cont)

associative : {R : Set} -> (Z : Set) -> {A B C : Set}  {f : A  M R B}  {g : B  M R C}  bind g ∘ bind f ≡ bind (bind g ∘ f)
associative Z = refl

ContMonad : (R : Set) -> Monad (M R)
ContMonad R = record { bind = bind; associative = associative }

I'm note sure, though, if it's necessary to eagerly apply all implicit arguments because, for example, there could be more implicit arguments in the type of the record field, or the implicit arguments could be in different orders. Although, I couldn't find a working example of something like that.

What's the actual reason for eagerly applying all implicit arguments when the required type has implicit arguments?

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.