直積型
複数の値を同時に保持するデータ構造
TSでは普通にobjectで定義したような型はこれになるのか?
$ a\times b種類の値を持つ
code:hs
-- 結合律
assocL2R :: Product (Product a b) c -> Product a (Product b c)
assocL2R (Product (Product a b) c) = Product a (Product b c)
-- 結合律
assocR2L :: Product a (Product b c) -> Product (Product a b) c
assocR2L (Product a (Product b c)) = Product (Product a b) c
-- 交換律
commute :: Product a b -> Product b a
commute (Product a b) = Product b a
言語例
sml
code:ml
datatype person = Person of string * int
Haskell
code:hs
data Product a b = Product a b
参考