Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow instance field declarations #2897

Closed
janmasrovira opened this issue Jul 15, 2024 · 0 comments · Fixed by #2916
Closed

Allow instance field declarations #2897

janmasrovira opened this issue Jul 15, 2024 · 0 comments · Fixed by #2916
Assignees
Milestone

Comments

@janmasrovira
Copy link
Collaborator

There should be a way to define a field to be an instance argument. E.g. we would like the applicative field in the Monad record to be an instance argument rather than an explicit argument.

trait
type Monad (M : Type -> Type) :=
  mkMonad  {
    applicative : Applicative M;
    bind : {A B : Type} -> M A -> (A -> M B) -> M B;
  };

Moreover, if we have the {{Monad M}} instance in scope, it should be possible to automatically infer the {{Applicative M}} and {{Functor M}} instances automatically.

Syntax

Options:

  1. Wrap only the name of the field with braces.
    trait
    type Monad (M : Type -> Type) :=
      mkMonad  {
        {{applicative}} : Applicative M;
        bind : {A B : Type} -> M A -> (A -> M B) -> M B;
      };
    
  2. Wrap only the field type with braces.
    trait
    type Monad (M : Type -> Type) :=
      mkMonad  {
        applicative : {{Applicative M}};
        bind : {A B : Type} -> M A -> (A -> M B) -> M B;
      };
    
  3. Wrap the whole field with braces.
    trait
    type Monad (M : Type -> Type) :=
      mkMonad  {
        {{applicative : Applicative M}};
        bind : {A B : Type} -> M A -> (A -> M B) -> M B;
      };
    

I'd personally argue that Option 1 is the best. It is easy to identify that the field is an instance argument and we do not add any potentially confusing braces to the type.

@lukaszcz lukaszcz self-assigned this Jul 17, 2024
@lukaszcz lukaszcz added this to the 0.6.4 milestone Jul 17, 2024
@paulcadman paulcadman modified the milestones: 0.6.4, 0.6.5 Jul 19, 2024
@janmasrovira janmasrovira linked a pull request Jul 25, 2024 that will close this issue
@lukaszcz lukaszcz assigned janmasrovira and unassigned lukaszcz Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants