What is Grammarly?
Grammarly’s AI-powered writing
assistant helps you make your
communication clear and effective,
wherever you type.
200+
team members across offices
in San Francisco, New York,
Kyiv, and Vancouver
2,000+
Institutional and
enterprise clients
20M+
daily active users around
the world
Grammarly by the numbers
Let’s imagine a simple function
f(x) = sin(x)
KolibriOS / MenuetOS
declarativus, from past-participle stem of
Latin declarare, “to make clear, reveal,
disclose, announce”
Declare
In computer science, declarative programming is a
programming paradigm—a style of building the structure
and elements of computer programs—that expresses the
logic of a computation without describing its control flow.
Declarative programming
DSL
Domain-
Specific
Language
● SQL
● XML / HTML
● … many others
SQL
SQL (/ˌɛsˌkjuːˈɛl/ (listen) S-Q-L, /ˈsiːkwəl/
"sequel"; Structured Query Language) is
a domain-specific language used in
programming and designed for managing
data held in a relational database
management system (RDBMS)...
CODASYL Data Model
CODASYL Data Model
CODASYL Data Model
CODASYL Data Model
CAN RUN FASTER AFTER
UPDATE ✅ ✅
INTUITIVE CONTROLS
✅ ✅
INNOVATIVE SOLUTION AT
THE TIME ✅ ✅
EVERYBODY LIKES IT
❌ ✅
MVU / Elm
architecture
> State -> View -> Message -
Elm architecture / MVU
Model (State) View
f ( )=
John
Dough
OK
name: John
surname: Dough
Messages
Message
⏰
☁️HTTP
f ( )=
John
Doe
OK
name: John
surname: Doe
f()=message: SurnameFieldEdited “Doe”
The Ugly
The Bad
The Good
3
The Better?
❓
❓
❓
🧨
System.NullReferenceException
🧨 System.NullReferenceException
Transforms to the real nullable
Underlying type is the same
🧨 System.NullReferenceException
// won’t compile
🧨 Empty string
// won’t compile
Nullable + references + API = 🎁
🎁 Option monad
Some : value
None
❓
nice API
Try* Pattern
Try* Pattern
❓
❓
Try* Pattern
LanguageExt.Option<T>
LanguageExt.Option<T>
LanguageExt.Option<T>
🎁 Either (Result)
🎁 Either
LanguageExt
⒡unctional C#
Expressions
Expression: produces value or side
effects
Statement: produces only side effects
match
F#
111
2
43
E A D G B E
1 5 1 3 5 1
1
2
3
4
First-Class
Functions
First-Class
Functions
First-Class
Functions
First-Class
Functions
First-Class
Functions
Remember this guy?
This is him now
Which property of the item
Partial application
Functions composition Pipe-forward
LanguageExt
Algebraic
Data
Types
Algebraic
Data
Types
Algebraic
Data
Types
Algebraic
Data
Types
// won’t compile
// compiles ✅
// ... function implementation
Domain
Invariants
💼 Case #1
Parse,
don’t
validate
Server
Messages
👩🔬🧨👨
Valid ✅
Not Valid ❌
F#
JSON Parser
F#
JSON Parser
eDSL
● Declarative way of specifying JSON structure
● Invariants enforced at the domain boundary
d
What do we get?
Version
Distribution
💼 Case #2
⚙️
👩
👨
🎤
👩
🏫
👩
✈️
🧛
♂️
👨
🎨
1.2.5
1.1.6
1.3.3
x.x.x⚙️
● Precise control over the versions distribution
● Clear way to specify which version goes to
which user
Update Rules
1.1.6
1.3.31.2.5
Existing QL
for JSON
● Solutions for NoSQL DBs
● Bloated imperative syntax
● Json.NET LINQ requires code
deployments
● GraphQL is too massive
Building declarative tools using
declarative tools
● JSON-like, easy to remember, intuitive syntax
● Safe way to adjust behavior without code
deployment
● Straightforward way to tune rules behaviour
without changing configuration
What do we get?
Log Crawler 📒
● Select the whole line or go by each word
● Match by regex or substring
● Print to console or write to file
Log
Crawler
Domain
Types
Log
Crawler
Domain
Types
Discriminated Unions
Records
Log
Crawler
FParsec
Log
Crawler
Parsing
Log
Crawler
Parsing
Running parser on string
Log
Crawler
InterpretingMimics our query structure
Interpreting
Log
Crawler
Interpreting
Log
Crawler
Running
Repository: https://github.com/6ruce/log-crawler/
~100 Lines Of Code: Types + Parsing + Interpreting
Summary: Make the computer work for you
Compiler
Static
analyzer
Computer
DSL
eDSL
Linter
Type checker
IDE
Syntax
sugar
Runtime
Abstractions
Thank you!
Stay healthy!
Links:
Parse, don’t validate:
https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-
validate/
Railway-oriented programming:
https://fsharpforfunandprofit.com/rop/
Expressions vs. Statements:
https://fsharpforfunandprofit.com/posts/expressions-vs-
statements/
LanguageExt: Thinking functionally:
https://github.com/louthy/language-ext/wiki/Thinking-
Functionally
FParsec: Parsing library:
https://www.quanttec.com/fparsec/

Vitalii Braslavskyi - Declarative engineering