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

Don't export record constructor names #3328

Open
janmasrovira opened this issue Feb 13, 2025 · 3 comments · May be fixed by #3337
Open

Don't export record constructor names #3328

janmasrovira opened this issue Feb 13, 2025 · 3 comments · May be fixed by #3337
Assignees

Comments

@janmasrovira
Copy link
Collaborator

Context

It is a common pattern to define record types with a single constructor named mk<Type>. E.g.

type MyRecord :=
  mkMyRecord@{
    ...
 };

The suffix of mk is just qualifying to constructor to avoid conflicts with other record types. However, since Juvix already allows qualified names, perhaps it would be more adequate to use those and avoid unnecessary verbosity in the declaration site.

Proposal

There are several ways we could improve the most common pattern. We could choose any of these options:

  1. Do not export constructors named mk.
  2. Do not export single constructors.
  3. Do not export single constructors with record syntax. E.g. myConstr@{field1; ..};

For any of these cases the constructor would only be accessible through the type module. E.g. MyType.mk.

@lukaszcz
Copy link
Collaborator

lukaszcz commented Feb 13, 2025

The most uniform solution would be to not export any constructor names by default (like e.g. in Lean). This also would make name clashes less likely. Common data structures like lists could just have the constructors explicitly exported right after the definition:

type List A :=
  | nil : List A
  | :: : A -> List A -> List A;

open List using {nil; ::} public;
-- or
open List using {List constructors} public;

@janmasrovira
Copy link
Collaborator Author

The most uniform solution would be to not export any constructor names by default (like e.g. in Lean). This also would make name clashes less likely. Common data structures like lists could just have the constructors explicitly exported right after the definition:

type List A :=
  | nil : List A
  | :: : A -> List A -> List A;

open List using {nil; ::} public;
-- or
open List using {List constructors} public;

Approved

@janmasrovira janmasrovira self-assigned this Feb 14, 2025
@janmasrovira janmasrovira linked a pull request Feb 18, 2025 that will close this issue
@jonaprieto
Copy link
Collaborator

Nice, less verbose; please update the docs when you can. ;)

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