OCaml: check list of membership entries

If I 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 entry where start = Nounin the type conversion list?

Kind of like

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

Except that the syntax is not working.

+3
source share
1 answer
List.exists (fun x -> x.start = Noun) un

List.memcan be considered as a special case List.exists, where it is List.mem x ysequivalent List.exists ((=) x) ys. This way you can use List.existsfor more general membership criteria.

+5
source

Source: https://habr.com/ru/post/1717598/


All Articles