Domanda

Se ho definito i seguenti tipi:

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

Qual è il modo migliore per rispondere alla domanda " è il record in cui start = Noun nell'elenco di trasformazione del tipo?

Un po 'come

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

Tranne che la sintassi non sembra funzionare.

È stato utile?

Soluzione

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

List.mem può essere considerato solo un caso speciale di List.exists , dove List.mem x ys è equivalente a List.exists ((=) x) ys . Quindi puoi usare List.exists per criteri di appartenenza più generali.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top