KernelF: a functional core for domain-specific languages in JetBrains MPS

KernelF
Turku Centre for Computer Science
Mikhail Barash
Åbo Akademi Finland
a functional core
@mikhail_barash
for DSLs
Domain-Specific
Languages
KernelF: a functional core for domain-specific languages in JetBrains MPS
KernelF: a functional core for domain-specific languages in JetBrains MPS
KernelF: a functional core for domain-specific languages in JetBrains MPS
1997
John, CEO publishing company
left right
top bottom
1
page enumeration
margins
single page
range
open interval
20..30
40-
measurement units
mm cm inches
KernelF: a functional core for domain-specific languages in JetBrains MPS
KernelF: a functional core for domain-specific languages in JetBrains MPS
1999
KernelF: a functional core for domain-specific languages in JetBrains MPS
Hi,
We've just got new order, diary No: 1999/3456/32-A.
It's books, covers 250g/m2.
Left: 30 mm
Top: 15 mm
Right: 20 mm
Bottom: 1 in
Thanks,
secretary typesetter
some structure
2000
KernelF: a functional core for domain-specific languages in JetBrains MPS
Jane, developer
typesetter developer
2001
KernelF: a functional core for domain-specific languages in JetBrains MPS
start marker
end marker
row: start.row + 1
col: start.col + 6
row: start.row + 4
col: start.col + 8
error messages
typesetter
2002
1,2,20-30,40-
implemented “manually”error messages
2003
error messages
typesetter
developer
KernelF: a functional core for domain-specific languages in JetBrains MPS
2007
KernelF: a functional core for domain-specific languages in JetBrains MPS
typesetter
developer
cryptic error messages
DSL
without tailored IDE
will not
be used
2010s
Language workbenches
requires parsingtextual DSL
automates definition of languageslanguage workbench
implementing IDE is tedious
vital for adoption and success of languageIDE
automates creation of IDEs for languages
IDEA-level custom IDE
rich notation
custom auto complete
intentions (quick fixes)
domain-specific error messages
key representation of program abstract syntax tree (AST)
can be projected into different representations
text diagrams tables forms
textual form of code only meant for the programmer
but it is unambiguous
can look ambiguous
no parsing needed
http://mbeddr.com
Projectional editing How does MPS work?
“variable declaration”
expression
Embedding Expressions Language
into Page Margins Language
Pages Margins DSL with embedded expressions language
”variable declaration”
expression
enabling expressions into already defined Page Margins DSL
Embedding languages
embedding not in the sense “embedded DSL”
“internal DSL”
Scala
XML
Lang A
Lang B
neither A nor B change
should work even with conflicting syntaxes
non-invasive embedding
KernelF “expressions language”
Markus Voelter
Overview of KernelF
primitive types
arithmetical and comparison operations
higher-order functions
number
option types
attempt types
null values
exception handling
static types
user-defined types tuples
functional type inference
Boolean string
enum record
+ - * / == != > < >= <=
no generics
no algebraic types
built-in collections are generic
not designed for building abstractions abstractions – in host DSL
keyword-rich
many first-class constructs
enum with data all immutable
natural notation for mathematical expressions
Excel-style spreadsheet
within code
Number types
int float
too much focused on need of programmers
business domain doesn’t find them useful
no usual types
numbers with range and precision
number[10|20]{2}
number[0|inf]
number[-inf|inf]{0}
positive integer
integer, unlimited range
decimal with 2 decimal places, value between 10 and 20
number{2}
number[2.2|3.8] range as specified, precision derived
decimal with 2 decimal places, unlimited range
Type tags
additional information attached to a typetag checked by type system
display(airportCode : string)
require only capitalized strings
display(airportCode : string<capitalized>)
<!tag>unary tags doesn’t have the taghas the tag unspecified
n-ary tags set of ordered values easy normal hard
val simpleText : string<easy> = “I go to school.”
val normalText : string<normal> = “This is an abstract painting.”
val complexText : string<hard> = “We semi-classically quantize circular strings.”
<tag>
fun sendToProfessor(text: string<hard->)
fun publishInTwitter(text: string<easy+>)
fun printOnTShirt(text: string<normal>)
hard, normal, easy
easy, normal, hard
toAllUpper(s : string) : string<capitalized>
Option types
handle null values in a typesafe way
val x : option<number> =
if something
then 1
else none
a term in an expression evaluates to none the whole expression is none⇒	
test whether an option does contain a value isSome(x)
Attempt types error handling
type system support for error handling
base type
attempt type
error literals
attempt< baseType | err1, err2, ..., errN >
fun getWeather(city: string): attempt<number[-40|40] | timeout, notFound> =
if ... then getTemp
else if ... then error(timeout)
else error(notFound)
val displayDegrees : string =
try getWeather(“Helsinki”) => val + “ degrees”
error<timeout> => “Timeout”
error<notFound> => “Not found”
“payload”
to be handled by calling code
via metaprogramming
“Flexible” language
adding new first-class constructs
removing constructs
exchangeable primitive types
overriding syntax
new syntax for existing language constructs
replace primitive types with types from the domain
LISP extensibleRacket parser-based
extend the language, but not the IDE
syntactic style difficult for non-programmers only textual languages
language workbench
Natural language function calls
@syntax{ accelerate to @[to] with @[at] }
car.accelerate to 10 with 2
car.accelerate(10, 2)
ext fun accelerate (this: Car, to: int, at: int) = ...
also appears in autocomplete menu
positional arguments less easily perceived by business users
Stateful language effect tracking
expressions don’t have side effects
results of function calls can be cached
KernelF can be extended to support expressions with side effects
which functions can be cached?
effects read write idempotence
Stateful language boxes
immutable data can’t change a value after it’s been created
invent new name for new value
boxes do not require mutable version of all immutable data structures
immutable
its contents can change
box
val counter: box<int> = box(0)
fun increase() {
counter.update(counter.val + 1)
}
read effectmodify effect
counter.update(it + 1)
current content of the box
val a = list(1, 2, 3)
val b = a.plus(4)
1 of 47

Recommended

Arrays and Lists in C#, Java, Python and JavaScript by
Arrays and Lists in C#, Java, Python and JavaScriptArrays and Lists in C#, Java, Python and JavaScript
Arrays and Lists in C#, Java, Python and JavaScriptSvetlin Nakov
2.5K views23 slides
C++ Programming Language Training in Ambala ! Batra Computer Centre by
C++ Programming Language Training in Ambala ! Batra Computer CentreC++ Programming Language Training in Ambala ! Batra Computer Centre
C++ Programming Language Training in Ambala ! Batra Computer Centrejatin batra
180 views17 slides
Bitwise Operations in Programming by
Bitwise Operations in ProgrammingBitwise Operations in Programming
Bitwise Operations in ProgrammingSvetlin Nakov
1.7K views27 slides
C++ Programming by
C++ ProgrammingC++ Programming
C++ ProgrammingRounak Samdadia
1.1K views77 slides
Assmbly lang.lec 1 by
Assmbly lang.lec 1Assmbly lang.lec 1
Assmbly lang.lec 1SoNia ChAudhery
16 views31 slides

More Related Content

What's hot

C++ programming program design including data structures by
C++ programming program design including data structures C++ programming program design including data structures
C++ programming program design including data structures Ahmad Idrees
2.6K views51 slides
C++ PROGRAMMING BASICS by
C++ PROGRAMMING BASICSC++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSAami Kakakhel
186 views55 slides
21csharp by
21csharp21csharp
21csharpSireesh K
26 views6 slides
Basics of c++ by
Basics of c++Basics of c++
Basics of c++Madhavendra Dutt
1.4K views56 slides
Chap 01[1] by
Chap 01[1]Chap 01[1]
Chap 01[1]Hafiz Muhammad Azeem Sarwar
495 views26 slides
C Programming Training In Ambala ! BATRA COMPUTER CENTRE by
C Programming Training In Ambala ! BATRA COMPUTER CENTREC Programming Training In Ambala ! BATRA COMPUTER CENTRE
C Programming Training In Ambala ! BATRA COMPUTER CENTREjatin batra
50 views18 slides

What's hot(10)

C++ programming program design including data structures by Ahmad Idrees
C++ programming program design including data structures C++ programming program design including data structures
C++ programming program design including data structures
Ahmad Idrees2.6K views
C Programming Training In Ambala ! BATRA COMPUTER CENTRE by jatin batra
C Programming Training In Ambala ! BATRA COMPUTER CENTREC Programming Training In Ambala ! BATRA COMPUTER CENTRE
C Programming Training In Ambala ! BATRA COMPUTER CENTRE
jatin batra50 views
Denis Lebedev. Non functional swift. by Alina Dolgikh
Denis Lebedev. Non functional swift.Denis Lebedev. Non functional swift.
Denis Lebedev. Non functional swift.
Alina Dolgikh1.8K views
Computer Organization - Programming the basic computer : Machine Language, As... by Maitri Thakkar
Computer Organization - Programming the basic computer : Machine Language, As...Computer Organization - Programming the basic computer : Machine Language, As...
Computer Organization - Programming the basic computer : Machine Language, As...
Maitri Thakkar669 views
Basics of c++ Programming Language by Ahmad Idrees
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
Ahmad Idrees47.8K views
C language industrial training report by Raushan Pandey
C language industrial training reportC language industrial training report
C language industrial training report
Raushan Pandey8.8K views

Similar to KernelF: a functional core for domain-specific languages in JetBrains MPS

Remix Your Language Tooling (JSConf.eu 2012) by
Remix Your Language Tooling (JSConf.eu 2012)Remix Your Language Tooling (JSConf.eu 2012)
Remix Your Language Tooling (JSConf.eu 2012)lennartkats
1.2K views73 slides
gayathri.p.pptx by
gayathri.p.pptxgayathri.p.pptx
gayathri.p.pptxGayathriP95
36 views11 slides
Scripting in InduSoft Web Studio by
Scripting in InduSoft Web StudioScripting in InduSoft Web Studio
Scripting in InduSoft Web StudioAVEVA
10.1K views26 slides
Unit 1 c - all topics by
Unit 1   c - all topicsUnit 1   c - all topics
Unit 1 c - all topicsveningstonk
1.6K views59 slides
Software Language Design & Engineering: Mobl & Spoofax by
Software Language Design & Engineering: Mobl & SpoofaxSoftware Language Design & Engineering: Mobl & Spoofax
Software Language Design & Engineering: Mobl & SpoofaxEelco Visser
921 views76 slides
Lecture 01 introduction to compiler by
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compilerIffat Anjum
19.9K views33 slides

Similar to KernelF: a functional core for domain-specific languages in JetBrains MPS(20)

Remix Your Language Tooling (JSConf.eu 2012) by lennartkats
Remix Your Language Tooling (JSConf.eu 2012)Remix Your Language Tooling (JSConf.eu 2012)
Remix Your Language Tooling (JSConf.eu 2012)
lennartkats1.2K views
Scripting in InduSoft Web Studio by AVEVA
Scripting in InduSoft Web StudioScripting in InduSoft Web Studio
Scripting in InduSoft Web Studio
AVEVA10.1K views
Unit 1 c - all topics by veningstonk
Unit 1   c - all topicsUnit 1   c - all topics
Unit 1 c - all topics
veningstonk1.6K views
Software Language Design & Engineering: Mobl & Spoofax by Eelco Visser
Software Language Design & Engineering: Mobl & SpoofaxSoftware Language Design & Engineering: Mobl & Spoofax
Software Language Design & Engineering: Mobl & Spoofax
Eelco Visser921 views
Lecture 01 introduction to compiler by Iffat Anjum
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
Iffat Anjum19.9K views
Building DSLs On CLR and DLR (Microsoft.NET) by Vitaly Baum
Building DSLs On CLR and DLR (Microsoft.NET)Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)
Vitaly Baum545 views
The Ring programming language version 1.10 book - Part 7 of 212 by Mahmoud Samir Fayed
The Ring programming language version 1.10 book - Part 7 of 212The Ring programming language version 1.10 book - Part 7 of 212
The Ring programming language version 1.10 book - Part 7 of 212
Architecting Domain-Specific Languages by Markus Voelter
Architecting Domain-Specific LanguagesArchitecting Domain-Specific Languages
Architecting Domain-Specific Languages
Markus Voelter1.2K views
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba... by Sang Don Kim
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
Sang Don Kim883 views

More from Mikhail Barash

MODELS 2020 Tutorial on MPS - Supplementary Material 8 - TextGen by
MODELS 2020 Tutorial on MPS - Supplementary Material 8 - TextGen MODELS 2020 Tutorial on MPS - Supplementary Material 8 - TextGen
MODELS 2020 Tutorial on MPS - Supplementary Material 8 - TextGen Mikhail Barash
569 views49 slides
MODELS 2020 Tutorial on MPS - Supplementary Material 5 - Creating concept Ent... by
MODELS 2020 Tutorial on MPS - Supplementary Material 5 - Creating concept Ent...MODELS 2020 Tutorial on MPS - Supplementary Material 5 - Creating concept Ent...
MODELS 2020 Tutorial on MPS - Supplementary Material 5 - Creating concept Ent...Mikhail Barash
559 views16 slides
MODELS 2020 Tutorial on MPS - Supplementary Material 3 - Creating editors for... by
MODELS 2020 Tutorial on MPS - Supplementary Material 3 - Creating editors for...MODELS 2020 Tutorial on MPS - Supplementary Material 3 - Creating editors for...
MODELS 2020 Tutorial on MPS - Supplementary Material 3 - Creating editors for...Mikhail Barash
548 views8 slides
MODELS 2020 Tutorial on MPS - Supplementary Material 1 - Creating concept Entity by
MODELS 2020 Tutorial on MPS - Supplementary Material 1 - Creating concept EntityMODELS 2020 Tutorial on MPS - Supplementary Material 1 - Creating concept Entity
MODELS 2020 Tutorial on MPS - Supplementary Material 1 - Creating concept EntityMikhail Barash
549 views7 slides
Towards a mnemonic classification of software languages by
Towards a mnemonic classification of software languagesTowards a mnemonic classification of software languages
Towards a mnemonic classification of software languagesMikhail Barash
184 views14 slides
Worst practices for domain-specific modelling by
Worst practices for domain-specific modellingWorst practices for domain-specific modelling
Worst practices for domain-specific modellingMikhail Barash
363 views17 slides

More from Mikhail Barash(20)

MODELS 2020 Tutorial on MPS - Supplementary Material 8 - TextGen by Mikhail Barash
MODELS 2020 Tutorial on MPS - Supplementary Material 8 - TextGen MODELS 2020 Tutorial on MPS - Supplementary Material 8 - TextGen
MODELS 2020 Tutorial on MPS - Supplementary Material 8 - TextGen
Mikhail Barash569 views
MODELS 2020 Tutorial on MPS - Supplementary Material 5 - Creating concept Ent... by Mikhail Barash
MODELS 2020 Tutorial on MPS - Supplementary Material 5 - Creating concept Ent...MODELS 2020 Tutorial on MPS - Supplementary Material 5 - Creating concept Ent...
MODELS 2020 Tutorial on MPS - Supplementary Material 5 - Creating concept Ent...
Mikhail Barash559 views
MODELS 2020 Tutorial on MPS - Supplementary Material 3 - Creating editors for... by Mikhail Barash
MODELS 2020 Tutorial on MPS - Supplementary Material 3 - Creating editors for...MODELS 2020 Tutorial on MPS - Supplementary Material 3 - Creating editors for...
MODELS 2020 Tutorial on MPS - Supplementary Material 3 - Creating editors for...
Mikhail Barash548 views
MODELS 2020 Tutorial on MPS - Supplementary Material 1 - Creating concept Entity by Mikhail Barash
MODELS 2020 Tutorial on MPS - Supplementary Material 1 - Creating concept EntityMODELS 2020 Tutorial on MPS - Supplementary Material 1 - Creating concept Entity
MODELS 2020 Tutorial on MPS - Supplementary Material 1 - Creating concept Entity
Mikhail Barash549 views
Towards a mnemonic classification of software languages by Mikhail Barash
Towards a mnemonic classification of software languagesTowards a mnemonic classification of software languages
Towards a mnemonic classification of software languages
Mikhail Barash184 views
Worst practices for domain-specific modelling by Mikhail Barash
Worst practices for domain-specific modellingWorst practices for domain-specific modelling
Worst practices for domain-specific modelling
Mikhail Barash363 views
Reflections on teaching JetBrains MPS within a university course by Mikhail Barash
Reflections on teaching JetBrains MPS within a university courseReflections on teaching JetBrains MPS within a university course
Reflections on teaching JetBrains MPS within a university course
Mikhail Barash359 views
Language Workbench Language Wheel by Mikhail Barash
Language Workbench Language WheelLanguage Workbench Language Wheel
Language Workbench Language Wheel
Mikhail Barash921 views
Design concerns for concrete syntax by Mikhail Barash
Design concerns for concrete syntaxDesign concerns for concrete syntax
Design concerns for concrete syntax
Mikhail Barash536 views
JetBrains MPS: Typesystem Aspect by Mikhail Barash
JetBrains MPS: Typesystem AspectJetBrains MPS: Typesystem Aspect
JetBrains MPS: Typesystem Aspect
Mikhail Barash500 views
JetBrains MPS: Editor Aspect by Mikhail Barash
JetBrains MPS: Editor AspectJetBrains MPS: Editor Aspect
JetBrains MPS: Editor Aspect
Mikhail Barash440 views
JetBrains MPS: Structure Aspect by Mikhail Barash
JetBrains MPS: Structure AspectJetBrains MPS: Structure Aspect
JetBrains MPS: Structure Aspect
Mikhail Barash1.3K views
Xtext: type checking and scoping by Mikhail Barash
Xtext: type checking and scopingXtext: type checking and scoping
Xtext: type checking and scoping
Mikhail Barash990 views
Xtext: validation, quickfixes, custom formatting by Mikhail Barash
Xtext: validation, quickfixes, custom formattingXtext: validation, quickfixes, custom formatting
Xtext: validation, quickfixes, custom formatting
Mikhail Barash1.4K views
Xtend Programming Language by Mikhail Barash
Xtend Programming LanguageXtend Programming Language
Xtend Programming Language
Mikhail Barash2.6K views

Recently uploaded

DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -... by
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...Deltares
6 views15 slides
Software testing company in India.pptx by
Software testing company in India.pptxSoftware testing company in India.pptx
Software testing company in India.pptxSakshiPatel82
7 views9 slides
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs by
DSD-INT 2023 The Danube Hazardous Substances Model - KovacsDSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
DSD-INT 2023 The Danube Hazardous Substances Model - KovacsDeltares
8 views17 slides
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut... by
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...Deltares
6 views28 slides
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... by
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...Deltares
10 views32 slides
Roadmap y Novedades de producto by
Roadmap y Novedades de productoRoadmap y Novedades de producto
Roadmap y Novedades de productoNeo4j
50 views33 slides

Recently uploaded(20)

DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -... by Deltares
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
Deltares6 views
Software testing company in India.pptx by SakshiPatel82
Software testing company in India.pptxSoftware testing company in India.pptx
Software testing company in India.pptx
SakshiPatel827 views
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs by Deltares
DSD-INT 2023 The Danube Hazardous Substances Model - KovacsDSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
Deltares8 views
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut... by Deltares
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
Deltares6 views
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... by Deltares
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
Deltares10 views
Roadmap y Novedades de producto by Neo4j
Roadmap y Novedades de productoRoadmap y Novedades de producto
Roadmap y Novedades de producto
Neo4j50 views
Cycleops - Automate deployments on top of bare metal.pptx by Thanassis Parathyras
Cycleops - Automate deployments on top of bare metal.pptxCycleops - Automate deployments on top of bare metal.pptx
Cycleops - Automate deployments on top of bare metal.pptx
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... by Marc Müller
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Marc Müller37 views
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J... by Deltares
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
Deltares9 views
Copilot Prompting Toolkit_All Resources.pdf by Riccardo Zamana
Copilot Prompting Toolkit_All Resources.pdfCopilot Prompting Toolkit_All Resources.pdf
Copilot Prompting Toolkit_All Resources.pdf
Riccardo Zamana8 views
Neo4j y GenAI by Neo4j
Neo4j y GenAI Neo4j y GenAI
Neo4j y GenAI
Neo4j45 views
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... by Marc Müller
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
Marc Müller38 views
SUGCON ANZ Presentation V2.1 Final.pptx by Jack Spektor
SUGCON ANZ Presentation V2.1 Final.pptxSUGCON ANZ Presentation V2.1 Final.pptx
SUGCON ANZ Presentation V2.1 Final.pptx
Jack Spektor22 views
Consulting for Data Monetization Maximizing the Profit Potential of Your Data... by Flexsin
Consulting for Data Monetization Maximizing the Profit Potential of Your Data...Consulting for Data Monetization Maximizing the Profit Potential of Your Data...
Consulting for Data Monetization Maximizing the Profit Potential of Your Data...
Flexsin 15 views
360 graden fabriek by info33492
360 graden fabriek360 graden fabriek
360 graden fabriek
info3349236 views
Headless JS UG Presentation.pptx by Jack Spektor
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptx
Jack Spektor7 views
Fleet Management Software in India by Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable11 views
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... by Donato Onofri
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Donato Onofri773 views

KernelF: a functional core for domain-specific languages in JetBrains MPS

  • 1. KernelF Turku Centre for Computer Science Mikhail Barash Åbo Akademi Finland a functional core @mikhail_barash for DSLs
  • 7. John, CEO publishing company left right top bottom 1 page enumeration margins single page range open interval 20..30 40- measurement units mm cm inches
  • 10. 1999
  • 12. Hi, We've just got new order, diary No: 1999/3456/32-A. It's books, covers 250g/m2. Left: 30 mm Top: 15 mm Right: 20 mm Bottom: 1 in Thanks, secretary typesetter some structure
  • 13. 2000
  • 17. 2001
  • 19. start marker end marker row: start.row + 1 col: start.col + 6 row: start.row + 4 col: start.col + 8 error messages typesetter
  • 20. 2002
  • 22. 2003
  • 25. 2007
  • 29. 2010s
  • 30. Language workbenches requires parsingtextual DSL automates definition of languageslanguage workbench implementing IDE is tedious vital for adoption and success of languageIDE automates creation of IDEs for languages
  • 31. IDEA-level custom IDE rich notation custom auto complete intentions (quick fixes) domain-specific error messages
  • 32. key representation of program abstract syntax tree (AST) can be projected into different representations text diagrams tables forms textual form of code only meant for the programmer but it is unambiguous can look ambiguous no parsing needed http://mbeddr.com Projectional editing How does MPS work?
  • 34. Embedding Expressions Language into Page Margins Language
  • 35. Pages Margins DSL with embedded expressions language ”variable declaration” expression enabling expressions into already defined Page Margins DSL
  • 36. Embedding languages embedding not in the sense “embedded DSL” “internal DSL” Scala XML Lang A Lang B neither A nor B change should work even with conflicting syntaxes non-invasive embedding
  • 38. Overview of KernelF primitive types arithmetical and comparison operations higher-order functions number option types attempt types null values exception handling static types user-defined types tuples functional type inference Boolean string enum record + - * / == != > < >= <= no generics no algebraic types built-in collections are generic not designed for building abstractions abstractions – in host DSL keyword-rich many first-class constructs enum with data all immutable
  • 39. natural notation for mathematical expressions Excel-style spreadsheet within code
  • 40. Number types int float too much focused on need of programmers business domain doesn’t find them useful no usual types numbers with range and precision number[10|20]{2} number[0|inf] number[-inf|inf]{0} positive integer integer, unlimited range decimal with 2 decimal places, value between 10 and 20 number{2} number[2.2|3.8] range as specified, precision derived decimal with 2 decimal places, unlimited range
  • 41. Type tags additional information attached to a typetag checked by type system display(airportCode : string) require only capitalized strings display(airportCode : string<capitalized>) <!tag>unary tags doesn’t have the taghas the tag unspecified n-ary tags set of ordered values easy normal hard val simpleText : string<easy> = “I go to school.” val normalText : string<normal> = “This is an abstract painting.” val complexText : string<hard> = “We semi-classically quantize circular strings.” <tag> fun sendToProfessor(text: string<hard->) fun publishInTwitter(text: string<easy+>) fun printOnTShirt(text: string<normal>) hard, normal, easy easy, normal, hard toAllUpper(s : string) : string<capitalized>
  • 42. Option types handle null values in a typesafe way val x : option<number> = if something then 1 else none a term in an expression evaluates to none the whole expression is none⇒ test whether an option does contain a value isSome(x)
  • 43. Attempt types error handling type system support for error handling base type attempt type error literals attempt< baseType | err1, err2, ..., errN > fun getWeather(city: string): attempt<number[-40|40] | timeout, notFound> = if ... then getTemp else if ... then error(timeout) else error(notFound) val displayDegrees : string = try getWeather(“Helsinki”) => val + “ degrees” error<timeout> => “Timeout” error<notFound> => “Not found” “payload” to be handled by calling code
  • 44. via metaprogramming “Flexible” language adding new first-class constructs removing constructs exchangeable primitive types overriding syntax new syntax for existing language constructs replace primitive types with types from the domain LISP extensibleRacket parser-based extend the language, but not the IDE syntactic style difficult for non-programmers only textual languages language workbench
  • 45. Natural language function calls @syntax{ accelerate to @[to] with @[at] } car.accelerate to 10 with 2 car.accelerate(10, 2) ext fun accelerate (this: Car, to: int, at: int) = ... also appears in autocomplete menu positional arguments less easily perceived by business users
  • 46. Stateful language effect tracking expressions don’t have side effects results of function calls can be cached KernelF can be extended to support expressions with side effects which functions can be cached? effects read write idempotence
  • 47. Stateful language boxes immutable data can’t change a value after it’s been created invent new name for new value boxes do not require mutable version of all immutable data structures immutable its contents can change box val counter: box<int> = box(0) fun increase() { counter.update(counter.val + 1) } read effectmodify effect counter.update(it + 1) current content of the box val a = list(1, 2, 3) val b = a.plus(4)