的价值,我有一些价值观,我需要找出名单哪种值是第一: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