In software development, we often face the same problem over and over again. For example, when designing user-interfaces, we need to specify the layout of components; when designing financial systems, we need to detect various patterns in changing prices. The Domain Specific Language (DSL) approach is to design a language for the specific problem domain and then use it repeatedly to solve multiple instances of the same problem.
In this talk, we look how to think about DSLs in a functional way. This lets us focus on the domain. Rather than worrying about the syntax, we start by understanding what problems we actually want to model and what is the best way to do so. Along the way, we’ll look at three fun examples ranging from a language for building 3D objects to a language for detecting price change patterns.
7. Domain-specific language approach
Class of problems
Constructing 3D objects
Makefiles, stock price modelling, testing, …
Domain-specific language in F#
Primitives – basic building blocks
Composition – how to put them together
14. DSL for writing documents
Creating DSLs with F#
=====================
Key components of a DSL:
* **Model** describes the
structure of the domain
that we are modelling
* **Syntax** provides an easy
way for solving problems
using the DSL
Creating DSLs with F#
Key components of a DSL:
• Model describes the structure
of the domain that we are
modelling
• Syntax provides an easy way
for solving problems using the
DSL
16. Processing Markdown
Domain model
Understand the problem domain!
Using F# discriminated unions
Domain-specific language
Internal – just an F# library!
External – parsing Markdown is easy!
24. ❶ Understand problem domain
Primitives & Combinators
❷ Model the language using
Discriminated Unions
❸ Add convenient Syntax
Internal or External
tomas@tomasp.net | @tomaspetricek |