Intro to Opaque Types
Opaque Types are a fancy way of saying "custom type with a private constructor." We talk about the basics, how to get started, and some patterns for using Opaque Types.
PublishedApril 3, 2020
Episode#2
Opaque Types
Some patterns
- Runtime validations - conditionally return type, wrapped in Result or Maybe
- Guarantee constraints through the exposed API of the module (like PositiveInteger or AuthToken examples)
Package-Opaque Modules
Example - the Element type in elm-ui.
Definition of the Element type alias
elm-ui's elm.json file does not expose the internal module where the real Element type is defined.
Example from elm-graphql codebase - CamelCaseName opaque type