WurstScript
WurstScript copied to clipboard
[WIP] Type classes
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
Nice 👍
I'm not too sure about the name instance
since we frequently use it in the documentation to refer to a class instance.
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>>
?
I get this error when trying to compile forest defense: