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

Nominal equality of unmodified types #26

Open
wokalski opened this issue Jul 24, 2021 · 1 comment
Open

Nominal equality of unmodified types #26

wokalski opened this issue Jul 24, 2021 · 1 comment

Comments

@wokalski
Copy link
Contributor

Currently the types for all generated versions are nominally different, even if they are structurally the same.

Let's say that we have two atd files:

type person = {
  name: string;
  surname: string
}

type employee = {
  person: person;
  age: int
}

and

type person = {
  name: string;
  surname: string
}

type employee = {
  person: person;
  age: int;
+ title: string
}

The type person stays the same between both files (it's not even transitively modified). Currently this generates two types Version1.person and Version2.person. They are structurally the same but nominally different. Behind the scenes %identity is used to transform one to the other.

This has two cons:

  1. Less important: the implementation of stork doesn't leverage OCaml type checker as a sort of proof mechanism
  2. More important: When you write migrators there's a lot of repetition for nested fields (i.e. you have to run migrate on them even if they didn't change). e.g.:
    let convert_employee converter doc (from: OldVersion.employee): NewVersion.employee = {
      person = converter.convert_person converter doc from.person;
      age = from.age;
      title = "IC"
   }

instead of

    let convert_employee converter doc (from: OldVersion.employee): NewVersion.employee = {
      person = from.person;
      age = from.age;
      title = "IC"
   }
@wokalski
Copy link
Contributor Author

Solving this issue would require either hacking around or using atd as a library rather than as a binary. Notably it already includes a way to mark fields as aliases to generate code like type person = OldVersion.person = { ... } (if the alias was set to OldVersion)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant