Algebraic Data Type とは?
algebraic data type は、複数の値をまとめる product と、いくつかの選択肢を提供する sum として、他の型を組み合わせて構築される複合型です。sum type の値はその variant のうち正確に 1 つであり、それぞれが独自のデータを持てます。これにより、いくつかの形のいずれかを取りうるデータを正確にモデル化できます。
なぜ重要か
algebraic data type は、値が取りうる可能性の正確な集合を符号化することで、不正な状態を表現不能にします。pattern matching と組み合わせて、各 variant を明示的かつ安全に処理します。
関連ガイド
What Is a Sum Type?A sum type holds a value that is exactly one of several named alternatives, each potentially carrying differe…
What Is a Product Type?A product type groups several values together at once, like a struct or tuple, so a value carries all of its…
What Is Pattern Matching?Pattern matching inspects a value against a set of shapes, selecting a branch and binding parts of the value…