|
|
|
|
|
by weatherlight
941 days ago
|
|
Both languages encourage a concise, functional programming style but with different flavors and toolsets. They are comparable, in terms of verbosity. I think these are correct implementations of the tower of Hanoi. OCaml let rec hanoi n source target auxiliary =
if n > 0 then begin
hanoi (n - 1) source auxiliary target;
Printf.printf "Move disk from %s to %s\n" source target;
hanoi (n - 1) auxiliary target source
end
SML fun hanoi n source target auxiliary =
if n > 0 then (
hanoi (n - 1) source auxiliary target;
print ("Move disk from " ^ source ^ " to " ^ target ^ "\n");
hanoi (n - 1) auxiliary target source
)
function definition, if expressions, recursion are more concise in SML, string interpolation is nicer in OCaml |
|