如何在 ocaml 中为这种类型的列表定义新类型和类型?

How can I define a new type and a type for list of this type in ocaml?

我是 ocaml 的新手,已经定义了一个类型。

type options =
  | Rock
  | Paper
  | Scissors

我还想定义一个选项列表。这就是我尝试的方式

type opts = list options;

当我尝试将选项的文字列表传递给函数时,Merlin 给我这个错误

有什么想法吗?顺便说一句,我正在专门使用 ReasonML,但我认为这并不重要。

这是翻译回 ocaml 的整个函数。

let compGuess () =
  let rec aux opts k =
    match opts with
    | [] -> [Rock]
    | x::[] -> x
    | h::t -> (match k = 1 with | true  -> h | false  -> aux t (k - 1)) in
  aux [Rock; Paper; Scissors] ((Random.int 3) + 1)

您的类型问题如下所示。你的比赛的第一个选择 return 是 opts 类型的东西。因此,第二个选择也必须 return 类型 opts。这意味着输入的头部 x 的类型为 opts。这意味着输入是一个选项列表。换句话说,您的函数应该采用选项列表。但是您正在传递一个选项列表。