←back to thread

Learn OCaml

(ocaml-sf.org)
203 points smartmic | 10 comments | | HN request time: 1.466s | source | bottom
1. 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 #
2. lairv ◴[] No.44401712[source]
In ocaml you would rather do something like this: let x_power_8 = (let a = x*x in let b = a*a in b*b);

a, b variables are just used for computing x_power_8, you don't need them outside of this scope. I think the point of the exercise is to use variable binding, though I agree the website doesn't explain much

3. cbarrick ◴[] No.44402055[source]
For historical context, I'm pretty sure "A Tour of Elm" is inspired by the similarly formatted and similarly excellent "A Tour of Go".

https://go.dev/tour/

4. ggerules ◴[] No.44402103[source]
Clicking on the introduction dropped you directly into a programming problem... where you actually needed to know some ocaml.

Context is needed... at least some explanation or bridge examples, like... why and what do I need to navigate this particular web landing page.

Website feels like an author exercise in ocaml for js web plugin.

5. 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 #
6. tempodox ◴[] No.44403072[source]
Whatever the purpose of that site is, “Learn OCaml” isn't it. That's a bad title, there is nothing in there that helps a beginner learn OCaml. It's more like a series of tasks where you already have to know OCaml to various degrees.

This is a much better starting point: https://ocaml.org/docs

Using the search engine of your choice, you can find many more sources just looking for "learn ocaml".

7. 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 #
8. vram22 ◴[] No.44403338[source]
I have been checking out the online books "OCaml from the very beginning" and "Real World OCaml".
9. octachron ◴[] No.44403850[source]
> This introduction doesn't really explain anything, as I guess it assumes you've learned OCaml elsewhere and are just here to practice.

Indeed the link is a not an introduction to OCaml but a demo instance of Learn-ocaml which is framework for building online exercise websites to complement (online or physical) lectures. This is why the instance is hosted on the OCaml Software Foundation website rather than ocaml.org: the demo is not targeted to learners but to teachers.

10. zulban ◴[] No.44433269{3}[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.