Reputation: 122432
If I have defined the following types:
type category = Noun | Verb | Adjective | Preposition;;
type transformation = {start: category; fin: category};;
What is the best way to answer the question "is the record where start = Noun
in the list of type transformation?
Sort of like
let un = [{start= Noun; fin= Noun}; {start= Verb; fin= Adjective}];;
List.mem {start = Noun; _} un;;
Except that syntax doesn't seem to work.
Upvotes: 3
Views: 1615
Reputation: 122429
List.exists (fun x -> x.start = Noun) un
List.mem
can be thought of as just a special case of List.exists
, where List.mem x ys
is equivalent to List.exists ((=) x) ys
. So you can use List.exists
for more general membership criteria.
Upvotes: 5