Greatest element of a list: Difference between revisions

Content deleted Content added
→‎{{header|Python}}: Simplified stream handling
Line 185: Line 185:


=={{header|OCaml}}==
=={{header|OCaml}}==
<ocaml>exception Empty_list
<ocaml>let my_max = function
[] -> invalid_arg "empty list"
let rec my_max = function
| x::xs -> List.fold_left max x xs</ocaml>
[] -> raise Empty_list

| [x] -> x
# my_max [4;3;5;9;2;3] ;;
| x :: xs -> max x (my_max xs)</ocaml>
- : int = 9


=={{header|Perl}}==
=={{header|Perl}}==