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

More efficient representation for datatype instances #158

Open
julianhyde opened this issue Jul 24, 2022 · 0 comments
Open

More efficient representation for datatype instances #158

julianhyde opened this issue Jul 24, 2022 · 0 comments

Comments

@julianhyde
Copy link
Collaborator

If a datatype has two type constructors, one with a value and one without, it may be more efficient to represent the one without as Java null. Consider, for example, the builtin option:

datatype 'a option = NONE | SOME of 'a

We currently represent all datatypes as a Java list. option is as follows:

  • NONE is Java list with one element: ["NONE"],
  • SOME 1 is Java list with two elements: ["SOME", 1].

Suppose that we represented it as follows:

  • NONE is Java null;
  • SOME 1 is Java Integer(1).

This seems to be more efficient. We have saved a List wrapper in both cases, and saved indirection when handling the datatype.

We cannot use this approach if a datatype has more than one unit constructor. For example builtin datatype order:

datatype order = LESS | EQUAL | GREATER 

Maybe instances of unit constructors can be represented as integers (similar to a C++ enum) and constructors with values can continue to be represented as Java lists.

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