Tomas Mikula - When your DSL Needs to Support User-Defined Functions

  Рет қаралды 529

Scala Days Conferences

Scala Days Conferences

Күн бұрын

Scala’s flexible syntax makes it a powerful host for embedding domain-specific languages (DSLs). As authors of a DSL, we define data structures to represent domain objects and we provide, quite easily, nice syntax to construct them. However, things get complicated once the domain objects, constructed by the users, include some form of functions. Provided there are good reasons to not have Scala functions inside our domain objects, we now need a data structure for representing functions and an ergonomic syntax for defining them. Needless to say, we would like to offload the bulk of typechecking our DSL programs to the Scala compiler.
In this talk, I will present a technique for implementing DSLs which support user-defined domain functions.
Firstly, domain functions will be represented as abstract arrows. Even though the primitive arrows will necessarily be specific to each particular domain, the operations for gluing simpler arrows into more complex ones are quite generic. For example, operations like sequential composition, parallel composition, branching, recursion will find their use in many domains.
Secondly, we will give the users of our DSL a familiar lambda syntax for defining domain functions. In practice, the user writes an anonymous Scala function on placeholder expressions. These expressions are parameterized by the types of the domain, so typechecking is delegated to the Scala compiler. We then translate the Scala function to a point-free (i.e. variable-free) composition of arrows of our domain. As the translation operates only on the generic glue code, we don’t have to reimplement it for every DSL. Instead, we will use a library solution from the Libretto project.
As a result, DSL implementors get a clean, point-free representation suitable for consumption by programs, whereas DSL users get to write domain functions using a familiar lambda notation.
Although the technique is applicable in languages other than Scala, I will highlight how some specifically Scala features make the result especially pleasant.

Пікірлер
Guillaume Martres - Polymorphic Function Types in Scala 3
40:14
Scala Days Conferences
Рет қаралды 925
Wojciech Mazur - Explaining Different Coroutine Flavours using Scala Native
37:16
Как подписать? 😂 #shorts
00:10
Денис Кукояка
Рет қаралды 5 МЛН
МЕБЕЛЬ ВЫДАСТ СОТРУДНИКАМ ПОЛИЦИИ ТАБЕЛЬНУЮ МЕБЕЛЬ
00:20
Jan-Pieter van den Heuvel - Saving Christmas Using Scala
42:34
Scala Days Conferences
Рет қаралды 517
Paul Matthews - Sounds of Structure - Music Modelling with ADT's
42:26
Scala Days Conferences
Рет қаралды 780
No, Einstein Didn’t Solve the Biggest Problem in Physics
8:04
Sabine Hossenfelder
Рет қаралды 131 М.
Nicolas Rinaudo - When is an ADT not an ADT?
37:25
Scala Days Conferences
Рет қаралды 1,5 М.
Andrea Mocci - Teaching Domain Specific Languages in Scala | Scala Days 2023 Seattle
41:18
Martin Kučera - Tyqu: Typesafe SQL Queries in Scala
36:57
Scala Days Conferences
Рет қаралды 956
Nicolas Stucki - Implementing a Macro
35:11
Scala Days Conferences
Рет қаралды 1,4 М.
Как подписать? 😂 #shorts
00:10
Денис Кукояка
Рет қаралды 5 МЛН