effekt
effekt copied to clipboard
Typeclasses
We should consider adding typeclasses or similar to prevent repeating code such as sorting datastructures, etc.
This seems to me like a straightforward transformation to codata:
- class definition -> interface definition
- instance -> top level object
- type constraints -> implicit parameters
I guess the tricky part would be inferring the correct instance.
A suggestion for syntax:
class C[A] {
// function declarations
}
instance C[T] {
// function definitions
}
// type constraints
def f [A] <C[A]> (a: A) = {...}
Another idea would be to add implicit parameters to Effekt and use regular codata to express type classes:
// implicit parameter of type A
def f () <a: A> = {...}
def main() = {
f() // passes implicit value iff there is exactly one value of type A in scope
}