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 supertypes of parameterized types #112

Open
nsbgn opened this issue Nov 9, 2022 · 0 comments
Open

Allow supertypes of parameterized types #112

nsbgn opened this issue Nov 9, 2022 · 0 comments

Comments

@nsbgn
Copy link
Contributor

nsbgn commented Nov 9, 2022

At the moment, parameterized types can only have sub- and supertypes by automatic extension of their parameters' sub- and supertypes. For example, if A <= B, then F(A) <= F(B).

However, it may sometimes be useful to have these types themselves be part of a hierarchy. Broadly, I see the following approaches:

  1. Allow a parameterized type to have a single, non-parameterized supertype. As in, A = TypeOperator() and F = TypeOperator(params=2, supertype=A).
  2. Allow a parameterized type to have a single parameterized supertype of the same arity. As in, F = TypeOperator(params=2) and G = TypeOperator(params=2, supertype=F).
  3. Allow a parameterized type to have an arbitrary supertype.

The use case demonstrated by @simonscheider and @EJTop today (cf https://github.com/quangis/ratios) was to have both ArchimedeanMagnitudes and ProportionalMagnitudes be Magnitudes. This corresponds to option 1. Intuitively, I also think the this one makes most sense. Mixing them would almost certainly be a bad idea.

However, I haven't throught through the implications in terms of the inference. In the meantime, it is possible to emulate such a type by using a TypeAlias with an EliminationConstraint --- the pseudo-supertype A would be interpreted as either one of its parameterized subtypes. So, instead of this:

A = TypeOperator()
F = TypeOperator(params=1, supertype=A)
G = TypeOperator(params=1, supertype=A)

You would do this:

F = TypeOperator(params=1)
G = TypeOperator(params=1)
A = TypeAlias(TypeSchema(lambda x: x [x << {F(_), G(_)}]))

Inferences would then be subtly different. Other relevant issues:

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