Data constructor
A data constructor is a language construct that creates a value of a data type, possibly with arguments.
Functional Programming in Scala, Second Edition
A data constructor is a named constructor that creates a value of an algebraic data type and may contain zero or more arguments.
- How it is used
- Models the possible forms of immutable lists and trees, then drives recursive operations through pattern matching.
- How deep it goes
- Defines constructors, shows polymorphic construction and nested patterns, and applies them to recursive list and tree functions.
- Examples
- Uses `Nil` and `Cons` lists, `Leaf` and `Branch` trees, tuple matching, and `sum`, `product`, and `size` functions.
- What you can do after
- Build it from scratch by declaring ADT cases and recursively constructing or destructuring lists and trees.
Read how Functional Programming in Scala, Second Edition explains data constructor →
Type-Driven Development with Idris
A language construct that creates a value of a data type.
- How it is used
- Uses constructors to build typed values and identify the cases handled by pattern matching.
- How deep it goes
- Defines constructors and illustrates enumerated, payload-carrying, recursive, and generic types; defers dependent types.
- Examples
- Demonstrates List with Nil and ::, Bool with False and True, and Nat with Z and S.
- What you can do after
- Builds data-type values and writes functions that handle constructor cases, as in xor and isEven.
Read how Type-Driven Development with Idris explains data constructor →
Related concepts
- algebraic data typeused by · An algebraic data type is a composite type whose values are formed from product structures, finite alternatives, or both through type constructors.
- import/export syntaxconfigured by · Module import and export syntax declares dependencies between modules and makes selected bindings available to other modules.
- patternused by · A pattern is a specification of criteria used to match values or text.
- data typepart of · A data type is a classification that specifies the values data can represent and the interpretations or operations applicable to them.
- state transitionimplements · A state transition is a change from one defined state of a system, object, or process to another according to an event, action, condition, or rule.
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.

