ヴァリアントの応用:列挙型

2008年1月22日
1 分

引数をとらないコンストラクタのみでヴァリアントを作れば,いわゆる列挙型になる。

# type color =
    Black
  | Blue
  | Red
  | Magenta
  | Green
  | Cyan
  | Yellow
  | White
  ;;
type color = Black | Blue | Red | Magenta | Green | Cyan | Yellow | White