代数的データ型
Algebraic data type
特に関数型プログラミングや型システムにおいて使われるデータ型
それぞれの代数的データ型の値には、1個以上のコンストラクタがあり、各コンストラクタには0個以上の引数がある
直積型の総和
再帰的な宣言もできる
code:ocaml
type node = Leaf of int | Branch of node * node
パターンマッチと相性が良い
総和を分解しながら処理を記述できる
code:ocaml
let rec depth tree = match tree with
Leaf _ -> 1
| Branch (a, b) -> 1 + max (depth a) (depth b)
Ocaml, Haskell, Rustなどで実装されている
https://ja.wikipedia.org/wiki/代数的データ型