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

Support explicit and inferred self types #21

Open
LPTK opened this issue Nov 24, 2021 · 1 comment
Open

Support explicit and inferred self types #21

LPTK opened this issue Nov 24, 2021 · 1 comment
Assignees
Labels

Comments

@LPTK
Copy link
Contributor

LPTK commented Nov 24, 2021

Example:

class A
  this: { x: int }
  method Foo = this.x  // ok

class B: A  // fine, transfers the `this`-type requirement

B{} // error: does not satisfy `this`-type

class C: A { x: 0 | 1 }

C{x = 0}   // ok

class A2
  // self inferred
  method Foo = this.x  // ok

A2{}  // illegal

class B2: A2

B2{}  // illegal

class C2: A2 { x: 0 | 1 }

C2{x = 0}  // ok
@LPTK LPTK added this to the Paper-parity milestone Nov 24, 2021
@LPTK LPTK added the feature label Nov 24, 2021
@LPTK LPTK removed this from the Paper-parity milestone Jan 3, 2022
@LPTK
Copy link
Contributor Author

LPTK commented Aug 31, 2022

I no longer think it's a good idea to infer self types (or receiver refinements, for that matter), but we could still use partially-specified self types with class-level type variables to achieve simple extensible programming as in @andongfan's project:

class Base {
  self: { eval: 'a -> int }  // used when typing methods below
  // Note that 'a is quantified at the level of the class instance
  ...
  fun eval: (Lit | Add('a, 'a)) -> int
    = ...
}

I think this actually helps to clarify the approach, and could be presented as the desugaring of the syntax we show in the SRC extended abstract.

To avoid confusion, we may want to capitalize class-level type variables, as in fun eval: (Lit | Add('A, 'A)) -> int, otherwise one could think the function is polymorphic in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🏗 In progress
Development

No branches or pull requests

2 participants