# Learning ocaml through a f# book?

**URL:** <https://discuss.ocaml.org/t/learning-ocaml-through-a-f-book/1696>\
**Category:** Learning\
**Created:** [March 10, 2018, 7:54pm UTC](https://discuss.ocaml.org/t/learning-ocaml-through-a-f-book/1696 "2018-03-10T19:54:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gimove](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@gimove](https://discuss.ocaml.org/u/gimove)\
**Post date:** [March 10, 2018, 7:54pm UTC](https://discuss.ocaml.org/t/learning-ocaml-through-a-f-book/1696/1 "2018-03-10T19:54:49Z")

</div>

Hello, i was wondering if it was a good idea to try to learn ocaml through this [Book](https://www.manning.com/books/get-programming-with-f-sharp), i heard that f# is pretty similar to ocaml, any thoughts on it ?

---

<div class="post-metadata">

**Author:** ![mars0i](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mars0i/32/1058_2.png) [@mars0i](https://discuss.ocaml.org/u/mars0i)\
**Post date:** [March 11, 2018, 5:42am UTC](https://discuss.ocaml.org/t/learning-ocaml-through-a-f-book/1696/2 "2018-03-11T05:42:35Z")

</div>

I don’t claim to know F#, but no one’s answered yet, and … before I decided to learn OCaml, I looked at F# as well. I would worry that trying to learn OCaml from an F# book would be frustrating.

My understanding is that F# has an indentation-based syntax as well as a more OCaml-like syntax. Also, an F# book would be likely to incorporate .Net library calls into examples. In addition to these libraries being unavailable in OCaml, my guess is that they’d use an objected-oriented style syntax which is uncommon in OCaml. I’m sure there are lots of other little differences between F# and OCaml. F# started from OCaml, but the sense I have is that over time its developers have felt free to add and change things in whatever ways seemed best to them.

So to the extent that parts of a book focus on syntax and concepts that are more or less shared between OCaml and F#, you might learn OCaml with an F# book, but there’s no reason to assume that an author would try to focus on what’s common to the languages.

If you are a moderately experienced programmer, and especially if you have some experience with functional programming, I’d recommend [_Real World OCaml_](https://realworldocaml.org/). Some things are out of date in the published version, but not much. I learned OCaml from it not too long ago, and not much has changed since then. If you like online reading you can read it for free. I like print for learning things like computer languages, and it’s a good thing to financially support the care that the authors and publishers put into the book if possible. (Publishers and editors don’t get enough credit for what they put into creating good books.) There is also a [new version](https://dev.realworldocaml.org/) of _Real World OCaml_ in the works that’s available online, but I’m not sure how much or what parts have been updated so far.

If you’re closer to being a beginning programmer or don’t feel at all comfortable with functional programming, [_OCaml from the Very Beginning_](http://ocaml-book.com/) is supposed to be good.

If you are stuck on a desert island with the F# book and a computer and an OCaml compiler, you could work through it, but otherwise, I suspect that using an F# book for OCaml will be uncomfortable. I don’t know the book you linked to, though, so who knows?

---

<div class="post-metadata">

**Author:** ![gimove](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@gimove](https://discuss.ocaml.org/u/gimove)\
**Post date:** [March 11, 2018, 12:02pm UTC](https://discuss.ocaml.org/t/learning-ocaml-through-a-f-book/1696/3 "2018-03-11T12:02:25Z")

</div>

Thank you for your reply, it was insightful and helpful (i actually didn’t thought about the difference of ecosystem between them and the fact that since it’s .Net it would be more OOP style than fp ).  
I own Ocaml From The Very Beginning, More Ocaml and Initiation à La Programmation Fonctionnelle En Ocaml (a french book), so i guess i’ll use them alongside the new version of RWO (i should be fine since i have some fp knowledge through scala.)  
Excited to get going and learn some ocaml !

---

<div class="post-metadata">

**Author:** ![UnixJunkie](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/unixjunkie/32/638_2.png) [@UnixJunkie](https://discuss.ocaml.org/u/UnixJunkie)\
**Post date:** [March 12, 2018, 7:26am UTC](https://discuss.ocaml.org/t/learning-ocaml-through-a-f-book/1696/4 "2018-03-12T07:26:12Z")

</div>

You don’t need a F# book.  
Just read the manual:  
[https://caml.inria.fr/pub/docs/manual-ocaml/index.html](https://caml.inria.fr/pub/docs/manual-ocaml/index.html)  
Especially chapters:  
Chapter 1 The core language  
Chapter 2 The module system  
Chapter 4 Labels and variants  
Chapter 5 Polymorphism and its limitations  
Chapter 6 Advanced examples with classes and modules

---

<div class="post-metadata">

**Author:** ![masoodahm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/masoodahm/32/1360_2.png) [@masoodahm](https://discuss.ocaml.org/u/masoodahm)\
**Post date:** [December 23, 2018, 7:48am UTC](https://discuss.ocaml.org/t/learning-ocaml-through-a-f-book/1696/5 "2018-12-23T07:48:03Z")

</div>

There are plenty of online resources on OCaml (Real world Ocaml, Think Ocaml) why not use them.  
For any one else looking for an answer to this same question well I am not an F# expert not even and intermediate developer but I have been lookin into it and F# has some syntactical differences that would not get you by in OCaml world. for example

```auto
let mutable name = "Richard";;

```

The above code will never work in OCaml because variables can not be made mutable. However it works in F# Compiler.  
Not to mention the difference of libraries and functions like `printfn` vs `Printf.printf`. F# uses `printfn` extensively in teaching where in OCaml you would use `print_int`, `print_string` or `print_float` for respective datatypes

---

<div class="post-metadata">

**Author:** ![MattWindsor91](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mattwindsor91/32/1327_2.png) [@MattWindsor91](https://discuss.ocaml.org/u/MattWindsor91)\
**Post date:** [December 23, 2018, 2:08pm UTC](https://discuss.ocaml.org/t/learning-ocaml-through-a-f-book/1696/6 "2018-12-23T14:08:58Z")

</div>

I came from F# to OCaml. There’s definitely a lot of overlap, and learning one is very helpful for learning the other later on, but I wouldn’t recommend trying to learn OCaml _from_ F# material. There are just too many differences, some of which have been mentioned above:

- Syntax is (by default) indentation-based in F#, which has no equivalent in OCaml
- Modules are much less powerful and flexible in F#, mostly because (IIRC) they’re effectively special types of .NET class (you’d probably use objects a lot more often in F#, but personally I’ve hardly ever resorted to them)
- F#'s object-oriented support is very different, being based on the .NET model, and arguably more prominent/more ‘useful’ than OCaml’s
- There are lots of features OCaml has that F# doesn’t (polymorphic variants, functors, PPX, straightforward native compilation, to name a few)
- There are lots of features F# has that OCaml doesn’t (.NET interoperability, type providers, units of measure, computation expressions, LINQ I think?)
- Generally, the ecosystem is completely different (OCaml has `dune` and `OPAM`, F# has `msbuild`/`dotnet` and `nuget`)
- Generally, the philosophy/use case is different. While both of them are quite pragmatic functional languages, and can be marketed as ‘secret weapons’ that enterprises can use for reducing complexity and improving the ability to reason about programs, F# is IMO more about pragmatically (and often gradually/incrementally) porting the benefits of functional programming to the _existing_ OOP-dominated .NET ecosystem (with interoperability and compatibility being important), whereas OCaml is its own separate entity that can develop and expand as desired.

---

<div class="post-metadata">

**Author:** ![mars0i](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mars0i/32/1058_2.png) [@mars0i](https://discuss.ocaml.org/u/mars0i)\
**Post date:** [December 25, 2018, 4:21am UTC](https://discuss.ocaml.org/t/learning-ocaml-through-a-f-book/1696/7 "2018-12-25T04:21:16Z")

</div>

> [@MattWindsor91](#):
>
> - There are lots of features F# has that OCaml doesn’t (… type providers, units of measure, …

fwiw a little bit of units of measure functionality might be provided in OCaml by [Owl’s metric system constants](http://ocaml.xyz/chapter/metric.html).
