Write a Blog >>
Fri 28 Sep 2018 14:40 - 14:50 at Frisco - Student Talks 2 Chair(s): Philipp Haller

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 [4] to extend this approach to support polymorphic functions. Unlike implicit functions [2] 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 [3] 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 [4], the remaining work to be done involves coming up with nice syntactic sugar [5] 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 - 15:00: Student Talks 2Scala 2018 at Frisco
Chair(s): Philipp HallerKTH, Sweden
14:40 - 14:50
Scala 2018
Guillaume MartresEPFL, Switzerland
14:50 - 15:00
Scala 2018
Max OvsiankinUC Berkeley, Eugene BurmakoTwitter, Inc.