effekt
effekt copied to clipboard
Implement Monomorphization optimization
Aims to implement monomorphization for effekt.
- [x] Simple polymorphism
- [x] Functions with multiple polymorphic types
- [x] Different orders of types
- [x] Polymorphic data types
- [x] Polymorphic effects
- [x] Local polymorphic functions
The following programs have been used to (manually) test the implementation and should give an overview of what already works.
Simple polymorphic functions
def a[A](in: A) = { in }
def b[B](in: B): B = { a(in) }
def c[C](in: C): C = { b(in) }
def d[D](in: D): D = { c(in) }
def main() = {
println(a(1))
println(d("32"))
}
Multiple type arguments + switching the order of types
def f[C, D](in: C, in2: D) = in
def g[A, B](in: A, in2: B) = { f[B, A](in2, in) }
def main() = {
println(g(3, "3"))
println(g('c', false))
}
Polymorphic data types
type Maybe[A] {
Nothing()
Just(x: A)
}
def f[T](a: T): Maybe[T] = Just(a)
def main() = {
val a = Just[Int](5)
val b = Nothing[Char]()
f(5)
()
}
Polymorphic effects
effect yield[A](x: A): Unit
def f() = {
do yield[Int](123)
do yield[String]("test")
}
def main() = {
try {
f()
} with yield[Int] {
x => println(x)
resume(())
resume(())
} with yield[String] {
x => println(x)
resume(())
}
()
}
This works for most programs now. There are still some open problems:
- [ ] Polymorphic recursion detection is more of a guessing game right now
- [ ] What to do with extern types
- [ ] A normalizer (?) bug, that removes
printlnin ImpureApp, causing some tests to fail (because the output is empty)