WurstScript icon indicating copy to clipboard operation
WurstScript copied to clipboard

[WIP] Type classes

Open peq opened this issue 5 years ago • 3 comments

This branch contains an implementation of type classes as described in the new generics design in #679.

TODO list:

  • [x] Instance Declarations
  • [x] Basic Type Bounds
  • [x] Type bounds in classes
  • [x] Dependent type classes
  • [x] Efficient search + namespacing (only search for instances in imported packages)
  • [x] implicit instances for classes: ToIndex, FromIndex (maybe: TableKey, TableValue, Hashable)
  • [x] Type Check: All functions implemented correctly
  • [x] Add check for diverging instance search
  • [x] Also search for supertypes
  • [x] Also search for methods in extended interfaces
  • [x] Overloads with extension methods / type classes should not give error.

Maybe add:

  • [ ] Complex inference (see Iterable example)
  • [ ] Translate casting to int using ToIndex and FromIndex type classes (better backwards compatibility)
  • [ ] Use type classes for iterators (for-loops)
  • [ ] Use type classes for operator overloading
  • [ ] Add an expression (or magic function) for obtaining type class instances and calling methods on them, like (implicitly<Show>.toString(42))
  • [ ] Automatically use existing methods and extension functions in instance declarations

peq avatar Jan 31 '20 00:01 peq

Nice 👍 I'm not too sure about the name instance since we frequently use it in the documentation to refer to a class instance.

Frotty avatar Jan 31 '20 18:01 Frotty

Yeah, will probably change it as it also introduces a new keyword and thus breaks StdLib tests.

Maybe just implements Show<int> or for <T: Show> implements Show<List<T>>?

peq avatar Jan 31 '20 18:01 peq

I get this error when trying to compile forest defense:

Frotty avatar Feb 15 '20 14:02 Frotty