liveBook · Manning

Data constructor

A data constructor is a language construct that creates a value of a data type, possibly with arguments.

How 2 Manning books explain it

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 →

What to know first

Related concepts

Questions about data constructor

What is data constructor?

A data constructor is a language construct that creates a value of a data type, possibly with arguments.

Which Manning books explain data constructor?

Functional Programming in Scala, Second Edition and Type-Driven Development with Idris.

What should I know before learning data constructor?

Manning books that teach data constructor usually introduce list first.

What kinds of data constructor are there?

Kinds of data constructor include pause.

What is data constructor part of?

Data constructor is part of data type. A data type classifies values by their permitted forms or representations and the operations or interpretations applicable to them.

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.