plume-lang / plume

Plume is a lightweight programming language that aims to be portable, powerful and easy to learn.
MIT License
13 stars 2 forks source link

Introducing brand-new type-extension system #16

Closed thomasvergne closed 6 months ago

thomasvergne commented 6 months ago

The current Plume type-system contains unsound inference rules, especially with its extensions' system. It has some issues during resolving instances with generics. 

To counter this issue, a new type-extension system should be introduced, a system like the Haskell one, which could enable fully sound inference and type checking on Plume. This comes with completely new syntax for extensions. 

Such a system would inherit from Haskell's one, meaning it would introduce new syntaxes changes such as the interface keyword, which would be used to define a Haskell class equivalent, and the extends keyword on type-generics to specify which interface should the generic inherit.

The new syntax should look like that:

interface<A> show<A> {
  fn show(x: A): str
}

extend show<str> {
  fn show(x) {
    // ...
  }
}
thomasvergne commented 6 months ago

A problem was issuing with type extensions: the generated code lacked forward declarations, as it needed mutual function calls (introduced and due to closure conversion step). To resolve such an issue, we moved to a labeled representation of the bytecode to better generate it afterward by resolving labels into virtual memory addresses.