The answer that Bartosz Milewski gives to the question about what are algebraic data types

© All Rights Reserved

21 views

The answer that Bartosz Milewski gives to the question about what are algebraic data types

© All Rights Reserved

- washing dishes lesson plan pdf
- 500_Sol_TAW10_1-2
- sap_abap_tutorial.pdf
- Manual de Programacion Motoman
- Untitled
- 02 Data Types
- Iec61131-3 Programmers Manual
- C++
- Original_1402895303_4_Content a - Operators and Variables in Java
- kb child study wecompress
- 5061326-SilkTestUserGuide
- 11 Alarm Logging En
- Mathematics B Course Paper III
- 1. Intro to C Prog_Part 2
- Manual PLC - 5 1785.pdf
- 10 PM Multiple Counter Plan
- 3rd quarter math unit plan
- cbse-class-11-computer-science-syllabus-2019-20.pdf
- 3C#-Numeric String and Data
- Fundamental Data Types

You are on page 1of 2

quora.com/What-are-algebraic-datatypes

Answered 224w ago · Author has 243 answers and 1m answer views

Any programming language that supports types must provide means of creating new user-

defined types. Amazingly, there are only two basic ways of combining types.

1. You can take two existing types and create a new one that contains both. A pair of int

and bool is such a combination. It contains both, an int and a bool, at the same time. It's an

AND of both types. If you look at types as sets of values, a pair describes a Cartesian

product of two sets. That's why these are called product types. A product of more than two

types forms a tuple. If you give names to elements of a tuple you create a record, or a

struct. These are all product types.

2. You can take two types and create a new one that contains either one of them. It's an OR

of both types. These combinations are called variants or unions. A union of int and bool

contains either an int or a bool, but not both. Again, if you look at types as sets, you call this

thing a disjoint sum. That's why these types are called sum types.

So we have products and sums -- multiplication and addition -- let's write them as * and +.

That sounds like beginnings of an algebra. We also have zero and one. Zero corresponds to

a void type: type that never has any values. One corresponds to a boring singleton type -- an

enumeration with only one member. But you immediately get more interesting types by

summing singletons. A sum of two singletons is a bool. A bool is a two in our algebra:

1+1=2

It can either be true or false: an enumeration of two values. All enumerations are sums of

singletons. Type char is an enumeration of 256 singletons (ASCII). Integer types are very

large enumerations.

Once you have the basic algebra of types, you can start writing equations and solving them.

Infinite data types, like lists or trees, are solutions of algebraic equations. For instance, a

list of 'a's is a solution to the equation:

x=1+a*x

You read this as: A list x is a data type that is a sum of a singleton (corresponding to an

empty list) and a product of 'a' with a list x. The latter corresponds to a pair of 'a' and a list:

a head of the list and the tail of a list. The head of the list is of type 'a'.

You can iterate this equation by substituting it into itself. The first iteration is:

x = 1 + a * (1 + a * x) = 1 + a + a * a * x

x = 1 + a + a * a + a * a * a + ...

1/2

This can interpreted as: A list is either empty (the singleton 1) or an element of type 'a', or a

pair of elements of type 'a', or a triple of elements, and so on... That pretty much

enumerates all possible lists of 'a'.

BTW, this analogy with algebra goes on. Function types, for instance, correspond to

exponentials.

Dharmendra Singh, Developer

Answered 224w ago · Author has 227 answers and 1m answer views

"Algebraic" refers to the property that an Algebraic Data Type is created by "algebraic"

operations. The "algebra" here is "sums" and "products":

"sum" is alternation (A | B,meaning A or B butnotboth) "product" is combination (A

B,meaning A and B together)

Examples:

data Pair = P Int Double isa pairof numbers, an Intanda Double together. The tag P is used

(inconstructorsand pattern matching) to combine the contained values into a single

structure that can be assigned to a variable. data Pair = I Int | D Double isjustone number,

either an Int orelsea Double.In this case, the tags I and D areused(in constructors and

pattern matching) to distinguish between the two alternatives.

Sums and products can be repeatedly combined into an arbitrarily large structures.

Algebraic Data Type is not to be confused with *Abstract* Data Type, which (ironically) is

its opposite, in some sense. The initialism "ADT" usually means *Abstract* Data Type, but

GADT usually means Generalized *Algebraic* Data Type.

2/2

- washing dishes lesson plan pdfUploaded byapi-291355677
- 500_Sol_TAW10_1-2Uploaded byalves_telmo8576
- sap_abap_tutorial.pdfUploaded byasdf
- Manual de Programacion MotomanUploaded byCokis Hdez S
- UntitledUploaded byapi-162641823
- 02 Data TypesUploaded bySourav Saha
- Iec61131-3 Programmers ManualUploaded byrfxfkjd
- C++Uploaded byMohmed Al Najar
- Original_1402895303_4_Content a - Operators and Variables in JavaUploaded bymukesh kumar
- kb child study wecompressUploaded byapi-457097840
- 5061326-SilkTestUserGuideUploaded byprakash
- 11 Alarm Logging EnUploaded byIsmael Gracia
- Mathematics B Course Paper IIIUploaded byaneeba
- 1. Intro to C Prog_Part 2Uploaded byThinagaran Mahendran
- Manual PLC - 5 1785.pdfUploaded bymcfaria20009603
- 10 PM Multiple Counter PlanUploaded byDiego Matos
- 3rd quarter math unit planUploaded byapi-286549827
- cbse-class-11-computer-science-syllabus-2019-20.pdfUploaded byArijit Das
- 3C#-Numeric String and DataUploaded byKenneth Sy
- Fundamental Data TypesUploaded byicul1
- Lecture1-3(Introduction to Programming Languages) (1)Uploaded bygohasap_303011511
- ABAP2Uploaded byraza_887
- Chapter 1 Introduction to DsUploaded byImran
- Software Development ProgramUploaded byMasood Rehman
- JS Typed ArraysUploaded bynipu90
- 11-12 SM1 FinalUploaded byodai1gor
- Zai 00004Uploaded byBalakrishna Vegi
- Arrays in JavaUploaded byRussel MASTER
- mathlesson-erinjennalaura 3Uploaded byapi-238465627
- Linear Thomas 2Uploaded byBBaire703

- Da Costa and Chuaqui (1988) On Suppes Set Theoretical PredicatesUploaded byLógica Usb
- Coltrane ChangesUploaded byLógica Usb
- Deleuze_and_Badiou_on_Being_and_the_Even.pdfUploaded byLógica Usb
- logic, neurons - 1943 Warren S. McCulloch, Walter Pitts "A logical calculus of the ideas immanent in nervous activity".pdfUploaded byArnaud Jammet
- Superseded Theories in ScienceUploaded byLógica Usb
- 1-s2.0-S0004370207000793-main.pdfUploaded bydylan
- Evolving Structures for Electronic Dance MusicUploaded byLógica Usb
- Bogue (2017) The Force That is but Does Not Act: Ruyer, Leibniz and DeleuzeUploaded byLógica Usb
- Africa__1961__Copernicus Relation to Aristarchus And To PythagorasUploaded byLógica Usb
- Lindley and McBride: HasochismUploaded byLógica Usb
- Lehmann__1981__Algebraic Specification of Data Types__A Synthetic Approach.pdfUploaded byLógica Usb
- Dijkstra A.-Essential Haskell.pdfUploaded byLógica Usb
- Lindenmayer (1967): Mathematical Models for Cellular Interactions in DevelopmentUploaded byLógica Usb
- Kechris: Set Theory and Uniqueness for TrigonometryUploaded byLógica Usb
- Heideggerian Thought in the Early Music of Paul HindemithUploaded byGabriel Chwojnik
- A_gentle_introduction_to_argumentation_s.pdfUploaded byLógica Usb
- Kile Jones: Analytic versus Continental PhilosophyUploaded byLógica Usb
- Church: Comparison of Russell's Resolution of the Semantical Antinomies with that of TarskiUploaded byLógica Usb
- 12_02Goldfarb.pdfUploaded byLógica Usb
- Droplets as Liquid RobotsUploaded byLógica Usb
- What is Functional Reactive ProgrammingUploaded byLógica Usb
- Ulrich Berger a , Wilfried Buchholz , Helmut Schwichtenberg: Refined program extraction from classical proofsUploaded byLógica Usb
- Thomas Meagher: Dwayne Tunstall as Africana PhilosopherUploaded byLógica Usb
- What is Object Oriented Programming and Functional ProgrammingUploaded byLógica Usb
- Stephen Walsh. Stravinsky: Oedipus Rex. reviewUploaded byLógica Usb
- Substance and Process Leibniz and WhiteheadUploaded byLógica Usb
- Digital Art: A Long HistoryUploaded byLógica Usb
- Mückenheim: Source Book of TransfinityUploaded byLógica Usb

- Principles of RadarUploaded bymas3565560
- 3 KINEMATICS.pdfUploaded byArianeManlangit
- Dunlop 20kg Universal Tile AdhesiveUploaded byjayzaa00tpg
- Tough and Tricky Exponents and Roots QuestionsUploaded byriad
- DreamUploaded byMazhar Hussain
- Practica N 2Uploaded byEglinston Lozano Santos
- Fun - Nerdy Pick-up LinesUploaded byDarigan194
- Introduction to Oxidation Reduction Potential Measurement.pdfUploaded byanastasya357
- Pavement Materials_ SoilUploaded byEvandro Santiago
- Production of 14 MeV Neutrons Using Pyroelectric Crystals: Reconverting Solar Energy into Nuclear Fusion EnergyUploaded bySEP-Publisher
- 17_Polymers (New).pdfUploaded bythinkiit
- 1. MechanicsUploaded bynicky1213a
- Micro Four-point Probe General Application NoteUploaded byCARROUCHO62
- Foxboro Handheld Terminal HHT-AAEFNBUploaded byJossi Perez A
- Intro ThermodynamicsUploaded bysunny1312
- Heat trace design guide - ChromoxUploaded byjonathonwu
- PRESSURE VESSELUploaded byYonjon Subha
- Stabilizer Design Planning SPS v1 1 0 LRUploaded byTihomir Markovic
- Quanta-ray LASERSUploaded byKapila Wijayaratne
- Timber Frame Isometric ViewUploaded bysertackcdg
- b2fh PaperUploaded byDhruv Dharamshi
- Engineering BooksUploaded bypw
- Time Study to Compare Different Operation Cycles Included in Manufacturing of Components with Cylindrical BoresUploaded byInnovative Research Publications
- 136605456 Beam CatalogueUploaded byMinh Tuan Nguyen
- Solved Problems Ch1Uploaded byirshad224
- Ni alloy HTUploaded byManivannanMudhaliar
- WELLCAT.pdfUploaded byAngga Bayu
- Transformer Fluid - A Powerful Tool for the Life Management of an Ageing Transformer Population UMIDADE-2001_a_powerful_toolUploaded bylbk50
- ABB PS Range Brochure (May 2011)Uploaded byAndres Alva Justo
- AAI Jr. Executive IT 2011Uploaded byJeethender Kummari Kunta