# Comparison of programming languages (algebraic data type)

This article compares the syntax for defining and instantiating an algebraic data type (ADT), sometimes also referred to as a tagged union, in various programming languages.

## Examples of algebraic data types
### ATS

In ATS, an ADT may be defined with:
And instantiated as:
Additionally in ATS dataviewtypes are the linear type version of ADTs for the purpose of providing in the setting of manual memory management with the convenience of pattern matching. An example program might look like:

### Ceylon

In Ceylon, an ADT may be defined with:
And instantiated as:

### Clean

In Clean, an ADT may be defined with:
And instantiated as:

### Coq

In Coq, an ADT may be defined with:
And instantiated as:

### C++

In C++, an ADT may be defined with:
And instantiated as:

### Dart

In Dart, an ADT may be defined with:
And instantiated as:

### Elm

In Elm, an ADT may be defined with:
And instantiated as:

### F#

In F#, an ADT may be defined with:
And instantiated as:

### F*

In F*, an ADT may be defined with:
And instantiated as:

### Free Pascal

In Free Pascal (in standard ISO Pascal mode), an ADT may be defined with variant records:
And instantiated as:

### Haskell

In Haskell, an ADT may be defined with:
And instantiated as:

### Haxe

In Haxe, an ADT may be defined with:
And instantiated as:

### Hope

In Hope, an ADT may be defined with:
And instantiated as:

### Idris

In Idris, an ADT may be defined with:
And instantiated as:

### Java

In Java, an ADT may be defined with:
And instantiated as:

### Julia

In Julia, an ADT may be defined with:
And instantiated as:

### Kotlin

In Kotlin, an ADT may be defined with:
And instantiated as:

### Limbo

In Limbo, an ADT may be defined with:
And instantiated as:

### Mercury

In Mercury, an ADT may be defined with:
And instantiated as:

### Miranda

In Miranda, an ADT may be defined with:
And instantiated as:

### Nemerle

In Nemerle, an ADT may be defined with:
And instantiated as:

### Nim

In Nim, an ADT may be defined with:
And instantiated as:

### OCaml

In OCaml, an ADT may be defined with:
And instantiated as:

### Opa

In Opa, an ADT may be defined with:
And instantiated as:

### OpenCog

In OpenCog, an ADT may be defined with:

### PureScript

In PureScript, an ADT may be defined with:
And instantiated as:

### Python

In Python, an ADT may be defined with:
And instantiated as:

### Racket

In Typed Racket, an ADT may be defined with:
And instantiated as:

### Reason
#### Reason

In Reason, an ADT may be defined with:
And instantiated as:

#### ReScript

In ReScript, an ADT may be defined with:
And instantiated as:

### Rust

In Rust, an ADT may be defined with:
And instantiated as:

### Scala
#### Scala 2

In Scala 2, an ADT may be defined with:
And instantiated as:

#### Scala 3

In Scala 3, an ADT may be defined with:
And instantiated as:

### Standard ML

In Standard ML, an ADT may be defined with:
And instantiated as:

### Swift

In Swift, an ADT may be defined with:
And instantiated as:

### TypeScript

In TypeScript, an ADT may be defined with:
And instantiated as:

### Visual Prolog

In Visual Prolog, an ADT may be defined with:
And instantiated as:

### Zig

In Zig, an ADT may be defined with:
And instantiated as: