Upload
tomas-petricek
View
1.177
Download
1
Embed Size (px)
DESCRIPTION
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.
Citation preview
Domain Specific Languages
The functional Way
Tomas Petricek@tomaspetricek | www.fsharpworks.com
F# Software Foundation
http://www.fsharp.org
software stacks
trainings teaching F# user groups snippets
mac and linux community books and tutorials
consulting open-source MonoDevelop
contributions research support
cross-platform mailing lists
Kaggle• Interactivity• Machine learning• Data processing
GameSys• Time to Market• Social Gaming• Concurrency
Tachyus• Analysis &
reporting• Time to market• Oil & gas startup
Credit Suisse• Complexity• Financial models• DSLs
DSL = model + syntax
COMPOSING 3D OBJECTS
Domain-specific language approach
Class of problemsConstructing 3D objectsMakefiles, stock price modelling, testing, …
Domain-specific language in F#Primitives – basic building blocksComposition – how to put them together
http://tomasp.net/blog/2014/puzzling-fsharp/
GENERATING TEXT DOCUMENTS
Domain model & Processing
What is a text document? How can we process it?
BUILDING AN F# DSL
Operations on documents
Parse Read from Markdown format
Format Generate HTML output
Process Translate to Norwegian!
PROCESSING DOCUMENTS
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
PARSING MARKDOWN
http://manning.com/petricek2
Processing Markdown
Domain modelUnderstand the problem domain!Using F# discriminated unions
Domain-specific languageInternal – just an F# library!External – parsing Markdown is easy!
DETECTING PRICE PATTERNS
Declining pattern
Rounding top pattern
Multiple bottom pattern
Functional DSL style
Primitive classifiersDeclining priceRising price
Composing classifiersSequence and parallel patternsLinear regression
DETECTING PRICE PATTERNS
Summary
❶ Understand problem domain Primitives & Combinators
❷ Model the language using Discriminated Unions
❸ Add convenient Syntax Internal or External
[email protected] | @tomaspetricek | http://fsharpworks.com