Skip to content

Instantly share code, notes, and snippets.

@notgiorgi
Last active February 22, 2017 18:58
Show Gist options
  • Save notgiorgi/3857c55ab88d02a23d254056cacecb16 to your computer and use it in GitHub Desktop.
Save notgiorgi/3857c55ab88d02a23d254056cacecb16 to your computer and use it in GitHub Desktop.
Sum and Product types
  1. In type theory a Product type is a type made of a set of types compounded over each other. In Haskell we represent products using tuples or data constructors with more than one argument. The “compounding” is from each type argument to the data constructor representing a value that coexists with all the other values simultaneously. Products of types represent a conjunc- tion, “and,” of those types. If you have a product of Bool and Int, your terms will each contain a Bool and Int value.
  2. In type theory a Sum type of two types is a type whose terms are terms in either type, but not simultaneously. In Haskell sum types are represented using the pipe, |, in a datatype definition. Sums of types represent a disjunction, “or,” of those types. If you have a sum of Bool and Int, your terms will be either a Bool value or an Int value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment