Re: if expression and match expression
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <20151009162433.Horde.6AYNDseHDraUus7udaq-utT@webmail.in-berlin.de> |
Zitat von "Seung-jin Kim [email protected] [ocaml_beginners]" <[email protected]> (Fri, 9 Oct 2015 12:55:53 +0900) > First of all, > There was a typo in my very initial question. > my has_element1 should be > > let rec has_element1 l e = > match l with > | [] -> false > | h::t -> if e = h then true else has_element1 t e;; > > Anyway,, Seems everyone got my point. :-) First time to post this > group and very new to ocaml. > > I did with ( ) for my second match. > > utop[91]> let rec has_element2 l e = > match l with > | [] -> false > | h::t -> ( match h with > | e -> true > | _ -> has_element2 t e > ) > ;; I would prefer using indentation and to align hte '(' and the ')' vertically. Also I would even more prefer "begin" and "end" over '(' and ')'. Thats a readability-issue. But it seems, your problem could be solved without a second match-statement. But, just in case, one day you will need a nested one, you may remember my comment here. Of course it's a matter of taste, what I mendtioned here. Ciao, Oliver