From 12155c436f7e10ac0b5049554db8dba8779a1fe1 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Wed, 11 Jul 2018 21:30:50 +0200 Subject: Add the mem function Signed-off-by: Olivier Gayot --- my_list.mli | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'my_list.mli') diff --git a/my_list.mli b/my_list.mli index 4644a74..329efba 100644 --- a/my_list.mli +++ b/my_list.mli @@ -75,3 +75,12 @@ let rev_append l1 l2 = let rec flatten = function | Item(hd, tl) -> append hd (flatten tl) | None -> None + +(** Return true if the given elem is contained in the given list. *) +let rec mem elem = function + | Item(hd, tl) -> ( + match hd = elem with + | true -> true + | false -> mem elem tl + ) + | None -> false -- cgit v1.2.3