A Pathway to πŸ₯Ύ

Functional Programming

Static Typing

Developer Happiness πŸ€—

Why Elm, Gleam, (or F#) might be your next favorite language.

About Me πŸ§”β€β™‚οΈ

For five years I worked fullstack in Elm and F#, with some TypeScript sprinkled in.

@stoft

What This Presentation Is Not About πŸ€”

The advantages of functional programming such as:

  • Immutability by default
  • Function composition (|>)
  • Pure functions
  • etc.

They're all there, but there are tons of resources out there about them.

Enter the Next Level πŸ›—

β€œNo runtime exceptions.”

"Safe refactoring."

"Just follow the compiler"

Core Concepts That Change Everything πŸ’‘

Beyond classic FP advantages...

  • Developer-Friendly Compilers
  • Small Languages
  • Pattern matching
  • Type-Driven Development
  • Parse, Don't Validate
  • Make Impossible States Impossible
  • TEA / MVU Architecture

Developer-Friendly Compilers ❀️

Typescript

Property 'documentTyp' does not exist on type '{ id: string; name: string; documentType: string; appliesTo: number; s3Key?: string | undefined; query: { project?: string | undefined; unitType?: string | undefined; unitModel?: string | undefined; serialNumber?: string | undefined; }; }'. Did you mean 'documentType'?

Developer-Friendly Compilers ❀️


error: Unknown record field

  β”Œβ”€ ./src/app.gleam:8:16
  β”‚
8 β”‚ user.alias
  β”‚     ^^^^^^ Did you mean `name`?

The value being accessed has this type:
    User

It has these fields:
    .name

Guess who else loves them? LLMs.

Small Languages

  • Languages you can keep in your head. 🧠
  • Usually just one way to do something.
  • Elm has consistently removed syntax.
  • Gleam, inspired by Elm is small from the start (no if, just case).
  • F# is also small, but has support for OO which adds quite a bit.

Pattern Matching πŸ”

Multi-argument patterns

let result = case x, y {
    0, 0 -> "Both are zero"
    0, _ -> "First is zero"
    _, 0 -> "Second is zero"
    _, _ -> "Neither are zero"
  }

This is steroids for implementing complex logic.

Pattern Matching πŸ”

Exhaustive Checks

let result = case x, y {
    0, 0 -> "Both are zero"
    0, _ -> "First is zero"
    _, 0 -> "Second is zero"
  }

error: Inexhaustive patterns
   β”Œβ”€ /src/main.gleam:9:16
   β”‚  
 9 β”‚     let result = case x, y {
   β”‚ ╭────────────────^
10 β”‚ β”‚     0, 0 -> "Both are zero"
11 β”‚ β”‚     0, _ -> "First is zero"
12 β”‚ β”‚     _, 0 -> "Second is zero"
13 β”‚ β”‚   }
   β”‚ ╰───^

This case expression does not have a pattern for all possible values. If it
is run on one of the values without a pattern then it will crash.

The missing patterns are:

    _, _

Type-Driven Development (TDD++) 🧠

  • Define what’s possible using types.
  • Let the compiler guide implementation.

type Result(a, e) {
  Ok(a)
  Error(e)
}

fn parse_int(x: String) -> Result(Int, String) {
	...
}


Specification first development inside your code, not just at the boundaries.

Parse, Don’t Validate πŸ€”

Validation:

if (typeof x === "string" && x.startsWith("user:")) {
  // ...
}

Parsing (Gleam):
case parse_user_id(input) {
  Ok(id) -> // ...
  Error(_) -> // ...
}

Once parsed, everything downstream is safe by construction.

Make Impossible States Impossible 🀯


type Payment = { method: "card" | "cash"; cardNumber?: string };

🚫 Can still have

{ method: 'cash', cardNumber: '1234' }

βœ… Better type safety.

type Payment = { type: "cash" } | { type: "card"; cardNumber: string };

Make Impossible States Impossible 🀯

Gleam

// ❌
type Payment {
  Payment(method: PaymentMethod,card_number: Option(String))
}
type PaymentMethod {
  Card
  Cash
}
// βœ…
type Payment {
  Card(card_number: String)
  Cash
}

YouTube logo Making impossible states impossible

Make Impossible States Impossible 🀯

Phantom types! πŸ‘»

type User(t) { User(id: String) }
type IsAdmin
type IsReadonly

fn auth_admin(user: User(IsReadonly)) -> Result(User(IsAdmin), Nil) {
  ...
}

fn do_admin_stuff(user: User(IsAdmin)) {
...
}

Typescript can emulate this, but you can shoot yourself in the foot with a simple as.

TEA / MVU Architecture πŸ«–

The Elm Architecture / Model-View-Update


Model : State
↓
Update : Effect, Model β†’ New Model, New Side Effects
↓
View : Model β†’ View, Hooks for Side Effects


Guess where redux got some of its inspiration from?

Performance: More Than Pretty Types 🏎️

Benchmarks comparing Elm, Gleam, and others

Not to mention the Elm and Gleam compilers are super fast. As in 100k LOC in a few seconds fast.

Interoperability πŸ”—

  • They all compile to JS!
  • Gleam also compiles to Erlang.
  • F# also compiles to .NET


What You Can Build πŸ—οΈ

  • Anything JS except "native" (but Tauri/Electron).
  • F#: anything .NET can do including native.
  • Gleam: anything Erlang can do.

The Payoff 🎁

  • You will grow as a developer.
  • Refactors are safe by design.
  • You spend less time testing, more time thinking clearly.
  • Code that represents intent, not workarounds.
  • Fewer bugs, higher confidence.
  • Compilers working with you.
  • No nulls, no exceptions, no panics*.
  • Communities that value kindness and clarity.

Developer Happiness πŸ€—

Martin Janiczek

The Real Limitations πŸ€”

  • Elm: browser-only (more or less), smaller ecosystem.
  • Gleam: young ecosystem, Erlang/BEAM learning curve.
  • F#: quirky if you want OO and .NET, but a lot of power and flexibility.
  • JSON de-/serialization is a pain in the 🀐.


Not dealbreakers β€” just tradeoffs worth knowing.

πŸš€ The Next Level Awaits

Try one this week.

πŸŽ„πŸŽ„β˜ƒοΈπŸŽ„πŸŽ„πŸŽ„πŸŽ„πŸŽ„β˜ƒοΈπŸŽ„πŸŽ„

πŸŽ„πŸŽ„ Advent of Code πŸŽ„πŸŽ„

πŸŽ„β„οΈπŸŽ„πŸŽ„πŸŽ„πŸŽ…πŸŽ„πŸŽ„οΈπŸŽ„β„οΈπŸŽ„

Q&A - FP πŸ€”

  • Isn’t FP too academic?
    • Not anymore. None of these languages talk about monads, functors, applicatives etc.

Q&A - Type Systems πŸ€”

  • Even Java has static typing, what's the big deal?
    • The big deal is that these are "sound" type systems, they actually have your back.
  • Doesn't "typing" everything make writing code slower?
    • If you want to be "fast" you can skip it, type inference is 100% and works great.
    • But typing will help clarify your thought process.

Q&A - Ecosystem πŸ€”

  • What about ecosystem maturity? β†’ Strong enough for most needs, but it can be a problem.
  • LLMs are not as proficient in these languages as they are in TypeScript.
    • Giving them up to date references helps.

Q&A - TypeScript? πŸ€”

  • Doesn't e.g. TS have all this already? β†’ Yes, but it's not enforced. ts-belt, zod, etc. help a lot but they're not "batteries included" like Elm, Gleam, and F#.