Opaque type
An opaque type is a type whose representation and implementation details are hidden from code outside its defining abstraction boundary.
Modern C, Third Edition
An opaque data type is a type whose representation and implementation details are hidden from code that uses it.
- How it is used
- Uses hidden representations behind functional interfaces for streams and nonlocal control-flow state.
- How deep it goes
- Explains interface discipline and C typedef mechanics, but stops short of specifying either hidden representation.
- Examples
- Uses FILE* with fputc and fputs, and jmp_buf with setjmp and longjmp.
- What you can do after
- Evaluate/understand C interfaces without relying on opaque representation details or copying unsuitable typedef techniques.
Functional Design and Architecture: Examples in Haskell
An opaque data type is a data type whose representation is hidden from client code behind an abstraction boundary.
- How it is used
- Separates unstable private implementations from stable public interfaces in imperative modules and prevents invalid states in domain models.
- How deep it goes
- Explains representation hiding through C declarations and typed constructors, then addresses testing access and internal stability trade-offs.
- Examples
- Uses C opaque pointers, device definitions, invalid component construction, smart constructors, and internal modules.
- What you can do after
- Apply via module interfaces and smart constructors that hide representation, preserve invariants, and permit controlled implementation changes.
Read how Functional Design and Architecture: Examples in Haskell explains opaque type →
Modern C
An opaque data type is a type whose internal representation or purpose is hidden from the code that manipulates it.
- How it is used
- Uses hidden representations to explain C library streams, pointers, and thread identifiers through permitted operations.
- How deep it goes
- Defines interface-based abstraction and warns against representation dependence, but defers pointer internals and memory purpose.
- Examples
- Uses FILE* with fputc and fputs, manually reimplements puts, and identifies threads with thrd_t.
- What you can do after
- Apply it via C library interfaces while avoiding assumptions about hidden representations.
Functional Programming in Scala, Second Edition
An opaque type is a Scala type whose representation is equivalent to an underlying type within its defining scope but abstract outside that scope.
- How it is used
- Encapsulates state actions while preserving function-based representations for pure stateful APIs.
- How deep it goes
- Defines scope behavior, conversions, and runtime tradeoffs, but defers detailed language specification.
- Examples
- Uses State[S, A] as S => (A, S) and Rand[A] as a specialized state alias.
- What you can do after
- Build it from scratch by defining State with apply and run while retaining encapsulation without wrapper overhead.
Read how Functional Programming in Scala, Second Edition explains opaque type →
Related concepts
- std::once_flagincludes · A once_flag is a synchronization object that coordinates threads to ensure a one-time function invocation occurs only once.
- extensionused by · An extension is a language feature that adds functionality to an existing type without modifying its original definition.
- thrd_tincludes · thrd_t is the C11 opaque type used to identify a thread.
- jmp_bufincludes · jmp_buf is an opaque C library-defined type representing a saved execution environment for setjmp and longjmp.
- __FILE__includes · __FILE__ is a predefined C macro that expands to a string literal naming the current source file.
- contractused by · An API contract is a specification of the operations, data, and behavioral expectations that govern interactions between software components.
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.



