liveBook · Manning

Phantom type

A phantom type is a type parameter present in a type declaration but absent from the runtime representation of its values.

How 2 Manning books explain it

Functional Design and Architecture: Examples in Haskell

A phantom type is a type parameter that appears in a type declaration but not in the runtime representation of its values.

How it is used
Separates database computations and selects service implementations at compile time without changing their runtime representation.
How deep it goes
Explains marker types, type classes, and type applications, while stopping short of fully hiding runtime channel mismatches.
Examples
Uses `ValuesDB` and `AstroDB` markers plus `HttpAstroService` and `TcpAstroService` selectors.
What you can do after
Apply it via Haskell type applications and type classes to distinguish compatible-looking database or service computations.

Read how Functional Design and Architecture: Examples in Haskell explains phantom type →

Idiomatic Rust

A type-system technique that attaches a generic parameter to a type without storing a value of that parameter.

How it is used
Uses compile-time type tags when a generic distinction matters but its value need not be stored at runtime.
How deep it goes
Works through the unused-parameter error, PhantomData, construction, and specialized implementations.
Examples
Uses a Dog tagged with empty breed types, including a Poodle named Jeffrey.
What you can do after
Build it from scratch by adding PhantomData and defining type-specific Dog implementations.

Read how Idiomatic Rust explains phantom type →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.