links-lang / links

Links: Linking Theory to Practice for the Web
http://www.links-lang.org
Other
318 stars 42 forks source link

Fresh label #1148

Closed Orbion-J closed 1 year ago

Orbion-J commented 2 years ago

This grants the possibility to define local labels, ie labels that can only be used in a specific scope.

The user can define one or more local labels that will be bound in the scope with

fresh `A, `B {
   [ scope where labels `A and `B are bound ]
}

He can use the local labels so defined in the scope as any other effect label and he cannot use them outside that scope. A function, a value or a typename that has such a label in its type cannot escape the scope. When we leave the scope, we try to erase the label from the type and if it it possible (ie if the label as a polymorphic or absent presence) the function/value is available in the rest of the program, it's type being cleaned from any local label. Otherwise, the function/value/typename is removed from the context and trying to use it will cause an unknown variable or Unbound type constructor error. There's something that is still not perfect. The effectnames being inlined before typechecking, we can get a label going out of scope. This will be identified by the typechecker and will raise a local label ... is not bound error. It seems that the effectname has escaped the scope. Example

fresh `A {
      effectname E = {`A:Int} ;
}
typename T = () -E-> () ;
Type error: The local label `A<1> is not bound
In expression: typename T = () -E-> ().

Briefly, here's how the code works :

Remark for now if all labels are internally of the same type and then can be local or global, the parser only accepts local labels in effect related things

dhil commented 1 year ago

Superceded by #1169.