Should I Haskell or OCaml?
If anyone can weigh in with some thoughts, it’d be appreciated. I don’t have particularly clear-cut requirements here, but here are some things I have been working on, as well as other thoughts I have been having about this choice, that may influence someone’s advice.
Although I am not motivated primarily by a dislike for Python (I like Python most of the time), here 2 things that genuinely bother me about it:
* Getting tired of the lack of real static typing. I suppose I could/should set up a MyPy daemon for everything I do that’s more than a simple script, or try Pyre? I’m not sure how much of a pain that would be.
In any event, it’s still kind of annoying for the language to not actually include this concept. The type annotations feel tacked on (because they are) and at the end of the day, it’s still possible to get runtime errors that should have been checked at compile-time.
* The import and PYTHONPATH stuff is crazy. In particular, I feel like I am constrained to structure projects in a way that makes sense. I’ve just found a way that works for Flask web applications and I am sticking with it because fiddling with the structure too much leads to import errors.
Maybe I would have more gripes if I were smarter. Things I do like about Python:
Standard library seems pretty good (?), especially in terms of DSA (I’ve been joking lately that solving Leetcode problems is where Python really shines)
The code tends to be readable (or at least, it is possible for someone to write very clean, very readable code).
The main things I have been working on lately have involved PDF/document processing in the context of web apps. I also have some designs to do some ML/NLP stuff in a domain/industry where I have domain expertise.
My current thoughts:
Haskell has a lot of learning materials, and stuff like HaskTorch exists for my ML/NLP interests. Primary downside is that it’s purely functional, which means it can be less flexible and makes it less likely it can replace Python as my go-to language. Of course, that might be a plus from a learning perspective, as it would force me to learn to accomplish things in a purely functional way.
OCaml is more flexible in terms of paradigm, which has pluses and minuses from a learning perspective. Seems more likely to be a practical choice.
I would not say employment prospects are top-of-mind here. I don't think either are widely-used enough for it to matter; C++ would be a better thing to add to my resume for a lot of the jobs I am interested in; and I am of the general opinion and belief that I should prioritize foremost what I enjoy and have genuine interest in, both for QOL and because money will then follow.
51 comments
[ 3.1 ms ] story [ 81.0 ms ] threadFor personal interest - try both and see which one you like more.
> Primary downside is that it’s purely functional, which means it can be less flexible and makes it less likely it can replace Python as my go-to language.
Learn Haskell so that you can dispel this notion.
So I would recommend you check out F# which is like OCaml but runs on the Common Language Runtime. While it is really good on web platform, you might want to investigate the state of data science domain in F#. There are some guides here[1] and here[2].
1. https://fsharp.org/guides/data-science/
2. https://github.com/fsprojects/awesome-fsharp#data-science
Not that this probably matters/holds any relevance, but I worked at a startup using C#, and I liked the language itself.
- Library to manipulate PDF documents: https://github.com/johnwhitington/camlpdf
- Web framework: https://aantron.github.io/dream/
- Scientific computing library: https://ocaml.xyz/
Last, I wrote a couple of practical-focused OCaml guides:
- https://dev.to/yawaramin/practical-ocaml-314j
- https://dev.to/yawaramin/practical-ocaml-multicore-edition-3...
Care to join?
I made a small one that classified dinosaurs in school.
If you have interest in both OCaml and Haskell, you might also consider just learning Rust which borrows aspects from both of them. Rust traits aren't quite as powerful as Haskell typeclasses and its module system is definitely more limited than OCaml's, but if you write it in a more functional style you'll get exposed to a lot of similar patterns.
A lot of things in Haskell never really clicked for me until I spent some time getting comfortable with Rust.
I guess I figured I wanted to do a more academic language first, and that there may be a chance I'd have a practical use-case actually crop up for Rust at some point (in particular if I want/need to write/generate some WebAssembly, which may be the case for a project I may embark on).
Thanks for your input
But I find it hard to choose Haskell for practical projects because there are so many options so many cool ways of doing things and there is always that latest better approach and I find myself into a permanent research mode where I learn a lot and get not much done.
Ymmv
I'm just a hobbyist that enjoys programming, and I eventually wanted to expand beyond python. I looked at Haskell and read Learn You a Haskell and did some Exercism exercises but never got anywhere close to being able to use it for real projects. Have been trying to learn about Lisp lately and feel like I've come to a similar dead end.
On the other hand, both Go and Rust have felt fulfilling and practical, with static typing and solid tooling, cross compilations, static binaries, and dependency management that is just a huge breath of fresh air coming from python.
The ML / data science scene is nowhere near as developed as in Python, and I still lean on jupyter/polars/PyTorch here, but I think the candle project[0] seems very interesting. Compiling whisper down to a single CUDA-leveraging binary for fast local transcription is pretty cool!
[0]: https://github.com/huggingface/candle
Elixir was also something that seemed interesting. I like that it has a focus/specialty (real-time, highly concurrent systems), and its specialty is relevant to several of my interests.
> I looked at Haskell and read Learn You a Haskell and did some Exercism exercises but never got anywhere close to being able to use it for real projects. Have been trying to learn about Lisp lately and feel like I've come to a similar dead end.
Yeah, I did some Learn You a Haskell a while back and similarly felt it was too incoherent and disjointed. I intend to buy a physical book or two this time around.
> On the other hand, both Go and Rust have felt fulfilling and practical, with static typing and solid tooling, cross compilations, static binaries, and dependency management that is just a huge breath of fresh air coming from python.
If I was going to start a startup, or was tasked with building a new service at an existing company, Go would be my leading candidate. However, I view that choice as simply very practical; it's a reliable language that is in widespread production use, performs well, etc. But this is more about interest/fun. I haven't written much Go, but insofar as I have, I found it very tedious and somewhat awkward. And it's not a functional programming language, as far as I am aware.
Yeah, candle is pretty cool, and is one reason why Rust was also a candidate for me. Dropped it out of consideration because I basically am not motivated by any of the things that, to my understanding, motivate Rust, such as low memory footprint.
If you want a statically typed functional language learn F#. And can easily leverage the .net ecosystem for easy productiity. Or if you want something that introduces the concepts that you can learn in a weekend learn Elm. It's front end only, it's very opinionated, but it's tiny and a great langauge to learn to think in FP.
If you want a non statically typed functional language learn Clojure. Not ideal on ramp, if has the java ecosystem, and great concepts. If you really don't want to do that learn a Scheme or Common Lisp although ecosystem isn't as large.
Once you've learned one (or two) of those, then start exploring things like Haskell. But before then it's a terrible waste of time, and almost guaranteed you'll be turned off from learning it before you feel productive in it or that you got your money's worth from your effort.
I'm surprised to see all the F# recommendations! Definitely on the radar now.
I have to admit that I've really enjoyed rust, and I think it actually pairs well with python. But I'm sure you've heard plenty of rust evangelism, and as it wasn't one of your two candidates for this thread, I won't go any further.
If you're already comfortable with Python, check out Hissp's tutorials (in the docs). It's a Lisp hosted on Python, so you can focus on the Lisp concepts without getting so bogged down by learning a new standard library at the same time.
https://github.com/glich/hissp
Advantages over OCaml is I suspect a much larger footprint and the ability to tap into all of .NET (huge ecosystem). Plus your skills will be more portable than Haskell or OCaml.
Both Haskell and OCaml are exceptional languages but the ecosystem and market footprint is not great for either. Jane Street has done a lot to evangelize OCaml but it hasn't really moved the needle. Haskell is probably the most different being a lazy functional language. Definitely learn it but using it in real life will be harder.
Although job prospects are not the primary factor, I would like to hear more about this. Is F# widely-used? Are there a bunch of F# jobs and not quite enough people to fill them?
Thanks
edit: also, if you can recommend any physical books on F#, I would appreciate it
Thanks
The "reason" why people ask "what's the use of that" is that they just assume that writing bug-free and correct software is impossible and not worth trying.
IMO, Elixir is the functional Python. The lack of types in Elixir feels very similar to current Python. Pattern matching and guards instead of type annotations. No compile time checking. Dialyzer instead of MyPy. But unlike Python, Elixir is actively working on adding static typing that will be checked at compile time.
The language tooling, documentation, and testing is miles ahead of Python.
The language is enjoyable, easy to understand and read. It's very simple syntax. (only 15 reserved words)
You can find a lot of similar libraries in Elixir.
Django -> Phoenix
SQLAlchemy -> Ecto
Jupyter -> Livebook
Polars/Pandas -> Explorer
Numpy -> Nx
PyTorch -> Axon
SKLearn -> Scholar
XGBoost -> EXGBoost
Transformers -> Bumblebee
Prefect/ETL -> Broadway and Flow
PyO3 -> Rustler
All of this and you also get the benefits of BEAM VM. Which makes Elixir faster and more scalable than Python in majority of cases.
Yeah, yeah I was thinking about Elixir too, I like that it has a specialty (real-time, highly concurrent). It sounds like it also has a more developed ML/NLP ecosystem than I realized.
For ML, none of these are popular options. However, F# has bindings for Torch that are maintained by Microsoft.
All 3 are great choices though.
Along with his book: "Domain Modeling Made Functional" by Scott Wlaschin
I surveyed many free and paid-for references to build my foundation, before picking John Whitington's "Haskell From the Very Beginning" (https://www.haskellfromtheverybeginning.com), because it "takes a no-prerequisites approach to teaching the basics of a modern general-purpose programming language".
I am also using Replit's "free-tier" as my Haskell learning environment. Replit let me jump right into the fun of Haskell, while postponing dealing with installation/configuration nuances until absolutely necessary. This is also letting me do learning any time I have a free moment from wherever I last left off on any computing device I have handy, including my tablets or smartphone.
So far, my learning experience has been a joy.
If you decide on OCaml, Whitington also wrote "OCaml From the Very Beginning" (http://ocaml-book.com), which available via free pdf or HTML thanks to the OCaml Software Foundation, and looks to be structured similar to his Haskell book.
Hope this helps.
https://learnyouahaskell.com/
Python? You may be surprised to know one or two pending tricks about that programming language, take a look at Design of Computer Programs by Peter Norvig at Udacity [4]
Scala is a good option too, since you mentioned getting tired from lack of real statically typing. EPFL Extension School has a good one: Effective Programming in Scala (Also available for free at Coursera).
Hope that helps, and happy learning!
[1] https://www.edx.org/learn/computer-programming/delft-univers...
[2] http://www.cs.nott.ac.uk/~pszgmh/pih.html
[3] https://www.youtube.com/watch?v=rkZzg7Vowao
[4] https://www.udacity.com/course/design-of-computer-programs--...
I figure I'll need to try all of them (OCaml, Haskell, and F#) lol, will do a bit of learning and then build the same small test project in each probably. Starting with Haskell.
Thanks for the thorough response, will check out those resources
OCaml is not more flexible than Haskell. The primary differences are greedy vs. lazy evaluation.
Haskell is used in production in finance and military applications. It was previously used at Twitter and Facebook. Haskell lets you create heavily-abstracted, curried monads and define custom operators. Basically, every mathematician's dream-kitchen sink-swiss army knife-footgun. Code so readily esoteric than 5 people on the planet will be able to maintain it. ;)
OCaml is used in a smattering of niche MAANG backend services and in XenAPI and Coq.
Rust or Elixir+Erlang are more useful alternatives because they translate to job skills. If you want speed, resource efficiency, correctness, concurrency, and maintainability then Rust. If you don't care about correctness or speed, but want apparent simplicity and rapid development then use Go. ;)
Partly because I hadn't even heard of it until yesterday lol
> Don't blame the tools when you're not utilizing them. I hate to state the obvious, but discontent is unlikely to be solved by either novelty or becoming a student novice again.
True, but I think one also must learn new things, and it's normal to get bored of a language want to see what else is out there. Obviously, I will learn some new things about programming and software by learning FP, even if I never directly utilize one of the languages in a job.
> Rust or Elixir+Erlang are more useful alternatives because they translate to job skills. If you want speed, resource efficiency, correctness, concurrency, and maintainability then Rust. If you don't care about correctness or speed, but want apparent simplicity and rapid development then use Go. ;)
Yeah, as stated in one of my other comments, if I was building something for production, I think Go would be my default choice. But that's because it's practical; it's a boring and tedious language, in my admittedly minimal experience.
The Haskell ecosystem is somewhat larger than Ocaml's (more support, users, learning materials, libraries). The difficulty with Haskell is mostly that it makes abstraction so easy that you can be tempted to make your code too abstract. But if you can manage to KISS, it can feel like a safer, cleaner, faster Python. Haskell doesn't require you to code in pure functions, but it will let you know through the types that a function is not pure / is "in IO", and it has lots of features to let you easily do things purely that you would otherwise do in IO. That may lead to more of your code being pure in the end. F#'s main advantage is access to the C# ecosystem, though at the cost of possibilities for null pointers when calling C# libraries / .NET API's.
Thanks
> F#'s main advantage is access to the C# ecosystem, though at the cost of possibilities for null pointers when calling C# libraries / .NET API's.
Yeah this sounds like it would be really useful in a lot of situations
I only played with haskell, but liked a lot the language. The only downside was the 'cabal' versus 'stack' build tools unclear status. The official haskell.org site recommends installing both but I had incompatibility issues at the time.