的價值,我有一些價值觀,我需要找出名單哪種值是第一:OCaml的:尋找特定類型的
type my_types =
| MAlpha
| MBeta of int list
| MGamma of string * int
let find_first where what =
List.iter (fun m ->
| MAlpha ->
(* iterate frough "what" to find if it was asked to look and return it if it was *)
| (* do the same for all other types *)
) where;
;;
let main =
let where_to_find = [MGamma, MAlpha, MBeta] in
let what_to_find = [MAlpha, MBeta] in
(match (first_found where_to_find what_to_find) with
| MAlpha ->
(* should return this *)
)
;;
有沒有辦法這樣做不接觸各類MyTypefind_first - 是否可以比較兩個值的類型? 謝謝。
你是什麼意思的'List.create',你爲什麼給它兩個其他的名字? –
@PascalCuoq,修正了這個問題。所以,我有** where_to_find **,並且需要知道** what_to_find **首先存儲在** where_to_find **中的哪個類型。 – Slav