Adding polymorphic functions to Scala (Student Talk)
Methods in Scala are not first-class values: they cannot be passed around, only called. This is not a fundamental limitation since it’s always possible to wrap a method in a class and create an instance of this class (the wrapped method is usually called apply since Scala will automatically rewrite calls like f(x) to f.apply(x) if necessary). But requiring users to create a new class for every kind of method they wish to wrap in a value would be inconvenient and hard to abstract over, so the language comes built-in with scala.FunctionN classes that each contain an apply method with N parameters, combined with some syntactic sugar and special typing rules this is how Scala represents functions.
However, Scala methods support a rich set of features that are not expressible with functions: they can have type parameters, dependent parameters, implicit parameters, default values, multiple parameter lists, etc. Some of these limitations have now been addressed in Dotty (the experimental compiler slated to become Scala 3), in each case the trick is to find a type to abstract over these functions [1, 2, 3].
In this talk I will describe ongoing work  to extend this approach to support polymorphic functions. Unlike implicit functions  we cannot simply create a fixed number of classes for them since a polymorphic method can have an arbitrary number of type parameters with arbitrary bounds, and unlike dependent functions  we cannot represent them as refinements to scala.FunctionN since a polymorphic method cannot override a monomorphic method. The proposed solution relies on Scala support for structural types, since structural calls on the JVM are not efficient, this is made practical through special type erasure rules. A proof-of-concept implementation is available at , the remaining work to be done involves coming up with nice syntactic sugar  and designing type inference rules to make polymorphic functions convenient to use.
PhD student at EPFL in the LAMP group working on Dotty, the next-generation Scala compiler.
Fri 28 Sep Times are displayed in time zone: Guadalajara, Mexico City, Monterrey change
|14:40 - 14:50|
Guillaume MartresEPFL, Switzerland
|14:50 - 15:00|