Albeit little, installing SML still requires some anount of gymnastics, google searching, and copying stuff from SO, GH Gists, etc.
Yes, I agree broadly with the line of thinking that says- if you are learning FP, you must be willing to do these, but a beginner might be disheartened and turned away- especially as someone learning alone.
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
You SML code is incorrect, shows that you actually never coded anything in SML. SML requires that "if" always contains "else" clause (which is the norm for many functional languages). And this kind of stuff which makes SML unnecessarily verbose (OCaml has for operators, single line let definitions that do not require you to make use val and fun for different type definitions etc.).
I did Programming Languages, Part A, (to learn FP semantics) many years ago. It doesn't show I never coded anything in SML, it shows I made a mistake :/ .I no longer have Standard ML on my machine.
I thought having the `let` keyword encompass `fun` and `val.` was needlessly confusing. It's not concise. if `let` can mean so many things why not just do what Haskell did.
Again.. it not "so much more verbose." which was the initial point.
Functional programmers tend to use recursion instead of explicit loops with implicit state, and it's wise to regard for loops with suspicion since it can't return anything.
Standard ML as the language of instruction is a vehicle for teaching FP semantics, not imperative ones.
Also, Tower of Hanoi is a classic problem that's well suited for recursion.
Yes, I agree broadly with the line of thinking that says- if you are learning FP, you must be willing to do these, but a beginner might be disheartened and turned away- especially as someone learning alone.