2009-09-14 65 views
3

如果我定義了以下幾種類型:OCaml的:檢查記錄列表成員

type category = Noun | Verb | Adjective | Preposition;; 
type transformation = {start: category; fin: category};; 

什麼是回答這個問題的最好辦法「就是記錄下start = Noun型轉型的名單

有點像

let un = [{start= Noun; fin= Noun}; {start= Verb; fin= Adjective}];;  
List.mem {start = Noun; _} un;; 

除了語法似乎並沒有工作。

回答

5
List.exists (fun x -> x.start = Noun) un 

List.mem可以被認爲僅僅是List.exists的特例,其中List.mem x ys相當於List.exists ((=) x) ys。因此,您可以使用List.exists獲取更通用的會員標準。