2 ms·
Ah, this is solved in OCaml using the 'and' keyword: let rec even n = match n with | 0 -> true | x -> odd (x-1) and odd n =
by wtetzner 9y ago
Ah, this is solved in OCaml using the 'and' keyword:
let rec even n =
match n with
| 0 -> true
| x -> odd (x-1)
and odd n =
match n with
| 0 -> false
| x -> even (x-1)
Although personally I've never liked the idiom where everything at the top-level is a statement. Even in OCaml I usually define a 'main' function, and call it at the bottom of the file:
let main args = do stuff...
...
let () = main Sys.argv
- munificent 9y agoYes, more specifically, the "let rec" is what begins the series of mutually recursive definitions. The "rec" is a clue that this is specifically for supporting this exact recursive case. > Although personally I've never liked the idiom where everything at the top-level is a statement. For statically-typed languages, I'm not a huge fan of it either. But for dynamically-typed ones, I think it works out OK.