Skip to main content

Traits

Tagless Final is denotational semantics in disguise

·10 mins
Every trait in your hexagonal architecture is a tagless-final algebra. Every impl is an interpreter. You have been writing denotational semantics without knowing it. We trace the connection from Kiselyov’s paper through Scala’s Cats-Effect to Rust’s port traits, and show why the pattern that academics call ‘finally tagless’ is the same pattern that practitioners call ‘dependency injection.’

Syntax and Semantics 3. The Expression Problem

·6 mins
Adding a new type is easy in OOP, hard in FP. Adding a new operation is easy in FP, hard in OOP. Philip Wadler named this the Expression Problem in 1998. We show how it manifests in Rust and Scala, and tease the resolution.

Syntax and Semantics 2: Three ways to define what your code means

·7 mins
Your match expression is operational semantics. Your pure function is denotational semantics. Rust’s borrow checker is axiomatic semantics. Three formal frameworks, three ways to assign meaning to code, and you have been using all of them without knowing it.

Todo CLI in Rust 3. JSON persistence, contract vs implementation

·18 mins
Third part of the series: we define the persistence contract with a generic trait, implement two adapters (in-memory and JSON to disk), and delve into the difference between interface and implementation as the axis of hexagonal architecture.

The Forge of Typeclasses 🔥

·9 mins
We explore in detail what typeclasses are, how to define them in Scala 2, and how they are implemented in other languages such as Haskell and Rust. Through practical examples, we demonstrate how to model behaviors clearly and scalably using this powerful design pattern in functional programming. We also discuss automatic derivation and the improvements Scala 3 brings to this area.

First Steps in Rust 🦀

·5 mins
My first impressions of Rust from a functional programming background (Scala and Haskell). A mix of excitement, frustration, and a paradigm shift in thinking.