14
$\begingroup$

I'm reading a book about Haskell, a programming language, and I came across a construct defined "algebraic data type" that looks like

data WeekDay = Mon | Tue | Wed | Thu | Fri | Sat | Sun 

That simply declares what are the possible values for the type WeekDay.

My question is what is the meaning of algebraic data type (for a mathematician) and how that maps to the programming language construct?

  • 5
    This is not a mathematical term. It's explained at Wikipedia: http://en.wikipedia.org/wiki/Algebraic_data_type.2011-07-08
  • 0
    Discussion of the connection of algebraic data types to universal algebra in this Stackoverflow thread, [Haskell's algebraic data types](http://stackoverflow.com/q/16770/487781). The simple example given above doesn't demonstrate *constructors*, which can be related to functors in category theory.2011-07-08
  • 2
    @joriki I started reading the article on Wikipedia and I'll finish it before coming back to my question. Anyhow in the first line it says `In computer programming, particularly functional programming and type theory, an algebraic data type [...] is...`, in turn the article about _type theory_ says `In mathematics, logic and computer science, type theory is...`, so it seems that _algebraic data type_ has a definition in the field of _type theory_ that has a definition in _mathematics_ therefore is a mathematical term. ;)2011-07-08
  • 0
    The example you gave is really an example of a *sum* type, which is easy enough to explain in mathematical terms. There are more sophisticated algebraic datatypes, however.2011-07-08
  • 0
    @hardmath: The simple example does demonstrate constructors, of type `() -> Weekday`.2013-01-06
  • 0
    @plmday: We can agree for the sake of discussion that the "simple example" entails a *type* constructor as well as a *data* constructor, but I was pointing toward making a *more* mathematical connection between algebraic data types and category theory. See HaskellWiki articles [Category theory](http://www.haskell.org/haskellwiki/Category_theory), [Constructor](http://www.haskell.org/haskellwiki/Constructor), and also [Hask](http://www.haskell.org/haskellwiki/Hask) which details some mathematical pitfalls in making the connection.2013-01-07

2 Answers 2