gator icon indicating copy to clipboard operation
gator copied to clipboard

Add Support for Existential Types for Managing Generic Declarations

Open pauljoo28 opened this issue 4 years ago • 1 comments

We currently do not support type inferencing for declare statements. The following does not parse: declare float dot<t extends vec>(t x, t y);.

This is an issue in test-u/generics/tagw_tdeclare_inference.lgl.

pauljoo28 avatar Apr 03 '20 15:04 pauljoo28

Fortunately, the syntax here can be fixed (see #80). There's a deeper issue, however, which is why I've renamed this issue: the need for existential types!

Right now, we have to write, say, with vec2 T: declare float dot(T x, T y) for all of vec2, vec3, vec4, which is a pain to write and maintain. The old Linguine vec type would be nice to have again, but we need to support existential types; think of OCaml-style types and match statements. For example, then, we could write something like:

type vec is
| vec2
| vec3
| vec4

with vec T:
T addone(T x) {
  // OCaml-style syntax; I'm open to trying other syntax!
  match T with:
  | vec2 -> x + [1., 1.];
  | vec3 -> x + [1., 1., 1.];
  | vec4 -> x + [1., 1., 1., 1.];
}

For simplicity, we probably just want the possible resolution types to be explicit, as opposed to OCaml's more complex tuple type structure. There might be a better solution for this problem, but that's my suggestion and proposed solution -- let me know if you think of something better!

Checkmate50 avatar Apr 03 '20 22:04 Checkmate50