Extending an existing type in OCaml

后端 未结 4 968
栀梦
栀梦 2020-12-10 01:43

I\'ve been doing some OCaml programming lately to learn the language and to get more acquainted with functional programming. Recently, I\'ve started to think that I\'d like

4条回答
  •  伪装坚强ぢ
    2020-12-10 02:23

    Hey, these are supposed to be Algebraic data types, right?

    Right. And algebraic data types are constructed by tagged (aka discriminated) unions and products. What you want is just a (non-tagged) union, which is not an algebraic data type and isn't supported by Haskell. OCaml has polymorphic variants (see other answers).

    Typed Scheme does support non-tagged unions, so you may want to check it out.

提交回复
热议问题