Skip to content

Instantly share code, notes, and snippets.

@daveman1010221
Last active April 28, 2020 01:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daveman1010221/b51a56ba31f1e31d2f990c729a2bdf95 to your computer and use it in GitHub Desktop.
Save daveman1010221/b51a56ba31f1e31d2f990c729a2bdf95 to your computer and use it in GitHub Desktop.
PureScript Notes

PureScript Notes

Definitions

Preliminary

  • Type: A context that describes some value.

  • Sum type: A kind of user-defined type that is a boolean XOR of possible types, where only one is chosen for a given instantiation. Also called a disjoint union, a sum type is an example of a type with limited polymorphism, where each of the possible instantiations of the type is explicitly defined.

  • Product type: A kind of user-defined type that is a boolean AND of types.

  • Algebraic Data Type (ADT): A composition of sum types, product types, and/or primitive types, with potentially multiple varied data-type-constructors which, when called, return concrete instances of an algebraic data type.

Keywords

  • data: A definition for an algebraic data type. The data type may be instantiated by calling a data-type-constructor with appropriate arguments.

  • class: A set of abstract behaviors, a contract/interface specification. Any implementation of a given type-class must implement the set of behaviors defined by the class.

  • instance: A concrete behavioral definition. A type class may consist of multiple behaviors. Implementers of a class must provide definitions for all of the behaviors defined by the class.

  • type: A synonym for a type, given a different name. Contains no constructor definition.

  • newtype: Exactly one type constructor with one argument. A re-definition of an existing type that gives the type a new name.

  • derive: "To obtain actually or theoretically from a parent substance"; To auto-create an instance of a supported type class, based on a set of supported type classes, which include: Eq, Ord, Functor, Newtype, and Generic.Rep. Typically used with "instance".

There is no direct link between an algebraic data type and a type class, which defines abstract behaviors. A class instance is the mapping between a data type and a type class. The class instance defines an instantiation of a type class, a defined set of behaviors for a given data type, which act upon the data type. Modules often define a data-type and a type-class together, then provide instances of the class, creating the associations between data and class within the Module definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment