
040: Phantom Builder Pattern
Jeroen introduces the phantom builder pattern and how it enables new guarantees in Elm API design.
Audio is streamed directly from the publisher (cdn.simplecast.com) as published in their RSS feed. Play Podcasts does not host this file. Rights-holders can request removal through the copyright & takedown page.
Show Notes
Phantom types (happens at compile time, not runtime)
Helps avoid things like adding centimeters and inches
Joël Quenneville's phantom types talk from Elm in the Spring A Number by Any Other Name
Extensible records
Builder pattern
elm-graphqlSelectionSetscope type variableBrian Hicks' builder pattern talk Robot Buttons from Mars
withfunctionsPhantom builder is a state machine for your types
elm-reviewRule API uses phantom builderPhantom types discourse post on time package Simon Herteby
Snapshot test in Elm review for expected error messages
Possible operations with phantom extensible builders
- Add a new field
- Remove a field
- Change the type of a field
- Remove the previously existing phantom type and change it to an empty record (not extensible, just a hardcoded return type) i.e. Replace
What you can do with phantom builder
- Require something to be always called
- Forbid something being called more than once
- Cause other constraints dynamically after calling something
- Make function calls mutually exclusive
- Enable a function only if another one has been called