←back to thread

Learn OCaml

(ocaml-sf.org)
203 points smartmic | 2 comments | | HN request time: 0.458s | source
Show context
mtlynch ◴[] No.44401433[source]
As someone interested in learning OCaml, this felt like a pretty inaccessible introduction.

Having seen "A tour of Elm,"[0] I really prefer that style. The left-hand side (what English readers read first) is an explanation of the concept, then the right side is the code, and the explanation gives you enough details to complete the code.

This introduction doesn't really explain anything, as I guess it assumes you've learned OCaml elsewhere and are just here to practice.

I tried the first exercise, and it felt more like a math problem than an exercise to teach a programming concept:

>Suppose that a variable x exists and is an integer.

>Define a variable x_power_8 that uses three multiplications to calculate x to the power of 8. The only function you are allowed to call is the (*) operator.

>Hint: use auxiliary variables.

So, at first I thought I was supposed to just call multiply eight times, and then I realized that they said you can only call multiply three times. So, you're supposed to do let a = x * x; let b = a * a; let x_power_8 = b * b. But that feels really contrived to me and not like anything I'd write in a real application, even a toy one. If the idea is teaching variables, why not just ask me to declare a variable that represents x plus 1?

[0] https://a-tour-of-elm.axelerator.de/#JSFunctions

replies(7): >>44401712 #>>44402055 #>>44402103 #>>44402781 #>>44403072 #>>44403338 #>>44403850 #
zulban ◴[] No.44402781[source]
"that feels really contrived to me and not like anything I'd write in a real application"

If that bothers you, you shouldn't be learning ocaml. Look at the latest stack overflow developer surveys. A vast majority of developers and real applications never touch ocaml.

replies(1): >>44403090 #
1. tempodox ◴[] No.44403090[source]
> If that bothers you, you shouldn't be learning ocaml.

That's not what OCaml is like, at all. You clearly hate it, for whatever reason. Fine, have it your way. But popularity contests on SO are not an argument and they explain nothing.

replies(1): >>44433269 #
2. zulban ◴[] No.44433269[source]
If we're talking about "real applications" it absolutely matters. Almost nobody is writing "real applications" with ocaml, overwhelmingly so. That at least suggests there's great reasons why not. Anyone asking about the practicality of the language needs to know that basic fact.