Domain Specific Languages: The Functional Way
-
Upload
tomas-petricek -
Category
Technology
-
view
1.182 -
download
1
description
Transcript of Domain Specific Languages: The Functional Way
![Page 1: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/1.jpg)
Domain Specific Languages
The functional Way
Tomas Petricek@tomaspetricek | www.fsharpworks.com
![Page 2: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/2.jpg)
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
![Page 3: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/3.jpg)
![Page 4: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/4.jpg)
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
![Page 5: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/5.jpg)
DSL = model + syntax
![Page 6: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/6.jpg)
COMPOSING 3D OBJECTS
![Page 7: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/7.jpg)
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
![Page 8: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/8.jpg)
http://tomasp.net/blog/2014/puzzling-fsharp/
![Page 9: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/9.jpg)
GENERATING TEXT DOCUMENTS
![Page 10: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/10.jpg)
Domain model & Processing
What is a text document? How can we process it?
![Page 11: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/11.jpg)
BUILDING AN F# DSL
![Page 12: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/12.jpg)
Operations on documents
Parse Read from Markdown format
Format Generate HTML output
Process Translate to Norwegian!
![Page 13: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/13.jpg)
PROCESSING DOCUMENTS
![Page 14: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/14.jpg)
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
![Page 15: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/15.jpg)
PARSING MARKDOWN
http://manning.com/petricek2
![Page 16: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/16.jpg)
Processing Markdown
Domain modelUnderstand the problem domain!Using F# discriminated unions
Domain-specific languageInternal – just an F# library!External – parsing Markdown is easy!
![Page 17: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/17.jpg)
DETECTING PRICE PATTERNS
![Page 18: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/18.jpg)
Declining pattern
![Page 19: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/19.jpg)
Rounding top pattern
![Page 20: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/20.jpg)
Multiple bottom pattern
![Page 21: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/21.jpg)
Functional DSL style
Primitive classifiersDeclining priceRising price
Composing classifiersSequence and parallel patternsLinear regression
![Page 22: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/22.jpg)
DETECTING PRICE PATTERNS
![Page 23: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/23.jpg)
Summary
![Page 24: Domain Specific Languages: The Functional Way](https://reader035.fdocuments.net/reader035/viewer/2022062614/5474b8a9b4af9fa90a8b5747/html5/thumbnails/24.jpg)
❶ Understand problem domain Primitives & Combinators
❷ Model the language using Discriminated Unions
❸ Add convenient Syntax Internal or External
[email protected] | @tomaspetricek | http://fsharpworks.com