Re: if expression and match expression

"Jeremy Yallop [email protected] [ocaml_beginners]" <[email protected]>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.