liveBook · Manning

Final Tagless

As explained in Functional Design and Architecture: Examples in Haskell

Final Tagless is a functional design pattern that represents a program through an abstract interface interpreted by one or more implementations.

Final Tagless is a functional dependency-inversion pattern: business logic targets an abstract interface, while type-directed implementations supply the concrete behavior. The approach is also called mtl style and commonly uses type classes and phantom types. section 13.2.6 section 13.3

A small interface can define operations such as reporting meteors and asteroids. A type selector then chooses an implementation, allowing the same business logic to run through HTTP or TCP. section 13.2.6

Selecting an astronomy service

The runtime reads a reporting channel, maps TCP to meteorsApp @(TcpAstroService) or HTTP to meteorsApp @(HttpAstroService), and executes the chosen scenario. The business operation stays unchanged, but this simple version still carries ReportChannel through the interface and can fail when its value mismatches the selected instance. section 13.2.6

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Works through a simple mtl-style interface, interpreters, type selection, and runtime injection, but defers more elaborate type-level variants.
Examples
Uses AstroService operations, HTTP and TCP interpreters, meteor reporting, ReportChannel selection, and meteorsApp injection.
What it assumes
Assumes familiarity with functional interfaces and application effects, while introducing type classes, phantom selectors, interpreters, and dependency injection.
What you can do after
Apply the pattern by defining an interface, implementing interpreters, selecting one with a type marker, and injecting it at the boundary.
How it connects
Connects dependency inversion with type classes, phantom types, interpreters, ReaderT, free monads, and GADTs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Design and Architecture: Examples in Haskell. The section links point to the parts of the book it draws on.