Re: if expression and match expression
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <CAAxsn=H9YW-Fb49LcREZey_RHLEwseYhhTjTKcOUVf9isXDs2g@mail.gmail.com> |
On 9 October 2015 at 14:56, Hendrik Boom [email protected] [ocaml_beginners] <[email protected]> wrote: > So you'd recommend something like > > let rec has_element2 l e = > match l with > | [] -> false > | h::t -> h = e or has_element2 (List.tl l) e > ;; List.tl should usually be avoided, too, since it fails on empty lists. It's better to use the variable that's bound to the tail of the list by pattern matching.