Recorded live on twitch, GET IN / theprimeagen MY MAIN YT CHANNEL: Has well edited engineering videos / theprimeagen Discord / discord Have something for me to read or react to?: / theprimeagenreact
much like rust, there is definitely an initial hump, but apparently there is very little hump (i am positive pun intended here) if you come from another ml
I was a CS grad student in France in the 90s when caml-light, which was not ocaml yet, was the official language for teaching Programming 101. It is pretty amazing that 30 years later Ocaml is a new exciting things for cool guys like you.
The most interesting article I read about ocaml was an article on building a website as a series of micro-kernels. At first it was just one micro-kernel for the whole site but the article writer went one step further and made each endpoint it's own micro-kernel and the main one was just router to each sub-micro-kernel.
I actually started learn OCaml about a week ago because of one of your videos. I have to say, it is quite elegant to write. Also one benefit of it has been the greater understanding of recursion that's come out of not having access (at least by default) to mutability.
Once I finally setup Dune, its a pleasure to work with Ocaml. I use only a few features, I don't mind the OOP mess, my code has mostly pattern matchings.
My only brief encounter with Ocaml was ~20 years ago. It was an interesting FP, ML-derived language but rather lacking in the ecosystem and not multithreaded-friendly (back then). It felt like an academic project (and in a way it was).
Had a play around with Ocaml a few years ago. Loved it, was doing opengl stuff and got quite far but if I remember I couldn't get native compilation working correctly on windows so I was stuck with the JVM version. In a round about way it was a similar experience for me to Clojure, loved it (I (Like lisps (generally anyway)), ideally would be using it all the time but it's not a good fit for my use case because performance (though ofc Ocaml -> native is fast).
Ocaml has been designer around a static type system, Hindley-Milner with an "object oriented" extension. Its type system is as complex as Hindley-Milner' and this type system has been designed with together with a type inference algorithm. Typescript intends to provide a type system to a dynamically typed language. Typing a dynamic language results necessarily in a complex type system and the type inference can not be as neat as in languages designed around type inference from the beginning.
Yes and no: there's definitely warts to typescript's system, which refuses to apply unification in lots of cases, the lack of negative types, how generics can only be unbound on a function value not others (think Array) It's definitely a really impressive achievement, though! I don't think there's any type system as complex just in terms of crap it has to deal with.
Well, there are weirder stuff, and from what I seen I liked haskell more, but ocaml as haskells cousin - very nice to see some celebrity type people promoting some ML stuff :)
Man, I think I will pick up Ocaml, after Go, it seems like a more sensible Haskell, don't get me wrong, I like Haskell, but everything is wrapped in monads, because it feels like a leaky abstraction, or I am just too dumb to use it well.
The rust Fn discussion was interesting because i used to struggle with it until i read ab article that finally made it clear. Fn once is most specific and basically it has a lifetime capture that leaves it after a single execution. Fn mut is obvious and fn is any function that doesn't have either restriction. And i should mention once is most specific mut is in between and fn is everything that has neither issue
I'd say it's sorta the opposite, actually. FnOnce is the _least_ specific. Every Fn is a FnMut and every FnMut is a FnOnce. Fn is a pure function that you can call as many times as you want, and if you give the same value it'll always have the same output (not really because RefCells exist, but y'know.). FnMut is a function that the compiler can't necessarily prove is pure, but which you can still call repeatedly. FnOnce is what you use when you're only going to call the function once and want to be maximally general and includes "move" closures. So for example, Option::and_then takes a FnOnce because it'll never use it more than once.
I feel like Haskell is the gold standard for functional programming, and every other functional language is trying to make it actually usable :) Personally I'm torn between learning a low level language like Zig or Odin, or learning a functional language like Ocaml or Haskell.
Haskell was the first language I learned and for me it is very natural to write functional code. I feel Haskell is usable and awesome! And other functional languages are trying to accommodate imperative programmers, and that's fine, since it's the industry standard and most people are used to it. But don't underestimate Haskell!!!!
@SVVV97 fair. To be honest I'm not either, but I am trying to learn and OCaml has been a great help towards that. Lots of concepts to explore. Jane Street has a podcast where they talked a bit about dependant types.
Initially language internal translation but that changes at some point and you think I’m new language and translate back. That’s when you know your fluent. I used to dream in Chinese.
Just a heads up, Ocaml lacks ad hoc polymorphism (trait/interface). so if you like that, you're probably better go with haskell or idris, they have typeclass which kind of like rust's trait but more powerful.
Ocaml is very nice and has a style that some people prefer over Haskell. But it is very old and the room for a new FP language that is vastly better, is completely there. Using optimized ref counting (FBIP, Perceus) instead of/in addition to GC, modern syntax, modular implicits, better tooling, better error messages (elm should be the standard), more cohesive/consistent community etc.
i would write in ocaml, but it feels like the language has less of an ecosystem than Nim, which is saying something. plus the whole "use this rewritten version of the stdlib" isn't a good look imo
Ecosystem is fine, there are plenty of libraries for common tasks. You can just use the default standard library if you want, no one is forcing you to use the alternatives.
when people understand the benefit of types, that they help you to track your assumptions across your code base, then you will understand that anything less of a sound type system like in typescript or Go creates more problems than it solves, you might not see it at the beginning but they will bite your ass in the moment you least expect it.
OCaml just looks wrong to me. And I’ve programmed some weird esoteric languages like Forth, MUMPS and a lot of assembly. But these are all procedural languages. Camel Toe is a functional language and there for the syntax looks so convoluted and foreign to me. My mind is wired more digitally thus procedural thinking - makes sense for an Electronics Engineer. ML is more for abstract scientists I guess. Oh yeah Rust and refactoring is a pain in the arse! Rust allows you to really paint yourself in a corner and have to sand the whole floor in stead just the path back to the door and repaint that.
That's the cool part about learning new programming languages, you break down your resistance to different styles and start to appreciate what all the differences are!
@@TankorSmash well I never appreciated functional languages. It’s just not how my engineers brain is Wired. Like I said I’ve programmed in very esoteric languages like MUMPs, I adore assembly and Forth probably being one of the weirder ones; passing everything over a stack and the reverse Polish notation that all clicked for me after about a few days. Functional never clicked I guess it’s just too abstract for my way of thinking - when you did hardware design and lowlevel programming you can only do that in a procedural way, so I guess certain beains are wired in a certain way. Functional languages are probably fun and easy for mathematician who in turn do not tend to not feel comfortable in the low level procedural stuff as much h. But it’s cool that there are choices, and that’s good. And just sniffing at them is also important to see what clicks with you, what is around and what they are great at and suck at. There’s no perfect language after all. Although C is damn near to perfection 😉
@@CallousCoder I failed my uni stats math class twice, and spent 10 years writing relatively performant C++ for my games. I'm the furthest thing from a mathematician and I still found a lot of value in FP! The puzzle-piece like nature of it goes a long way for me, where you can just move parts around without worrying too much because of the purity is such a nice quality. But yeah, definitely not going to be for everyone, especially since it's _so_ different and strange!
@@TankorSmash it’s not a race but I think I suck more at maths 😂I was so happy when I barely passed the 2nd semester and maths was out after that. Integrals, algebra equations 🤮Applied mathematics is okay but that abstract theoretical stuff never worked for me. And my dad studied mathematics and he couldn’t even teach it to me, although he did better than the maths teachers I had. At some point in highschool I was called into the headmaster’s office and there sat my physics and mathematics teacher. And basically the question was if I had something against my maths teacher because I aced physics and chemistry and failed maths and failed it miserably. I told them that I had not problem with Johan (teachers and students were on a first name bases at that school), just that if he can’t teach the concept that for some reason it doesn’t click with me. And physics is very factual and I know that I derived a formula wrong if say for example something falls from the Eifeltower and breaks the sound barrier, that just doesn’t happen. With abstract maths I’m glad that there’s an outcome and done with it 😃 I even had to do a summer course to get into the EE program. Because technically you weren’t allowed if you didn’t elect maths. But luckily recommendations were great from my old school. And the projects I did spoke for themselves. And barely passed that course. It would’ve been a real dud if I hadn’t. Because EE was basically my only, “stay out of the military draft option left”. I wanted to study music as I was a professional musician already although self taught I did manage to get into audition for the Royal Conservatory. I already had a place at the Amsterdam Film academy but my passion was music. So I waited and waited and eventually word came that I hadn’t made the cut. By then my position at the film academy had been filled. But based on my film they said I could enroll next semester. Since I tinkered a lot with electronics (phreaking, hacking radio to listen in on police, making effects peddles) my dad suggested to do EE for a semester and then do the film academy. I never went to the film academy 😃Although I did end up working in film and tv and also write scores every now and then. But that EE diploma always was there to pay the bills. Where my musician and film friends all frequently rely on benefits 😖
@@CallousCoder u dont have to be even semi-good at math to program functionally. prime maybe has the level of a upper level high schooler and he is going just fine. its a common misconception that in order to program functionally u need to be some advanced math person.
At Harvard, computer science concentrators have to do a course that is just a semester in OCaml (intended to improve design and style), and it caused me-and everyone I know-so much PAIN.
I feel that ocaml introductions should start with excuses and disclaimers. "Sorry, we use ;; because when I designed the language, I spilled the coffee near my ; key". "We sincerely apologize for having separate set of operators for ints and floats; but uniform unary minus; we understand that this probably violates Geneva convention". "Please bring close your bucket for vomiting before reading this section". "Don't forget to tell your doctor that you were trying to ocaml, it will prevent tragic cases of misdiagnosis when you will eventually be hospitalized with severe eye bleeding"
I just think, unfortunately, the tooling is bad. Dune, esy, opam... and somehow everything interferes with the others. I like the language. But setting up projects feels just bad and brittle.
Good Video. I assume OCaml is now the new land of new programmers trying to replace JS and provide a C++ alternative (since we're all leaving Rust). This is a very good video especially the part about the OCaml community moving toward getting rid of the OCaml (incremental) Garbage Collector and compiling memory management baked right in it. I hated OCaml because of the GC. OCaml is like a french version of TKL + CamlLight. OCaml used to be (or is) a bad language for I/O applications (due to garbage collections) with horrible syntax and a bad OOP design. But if you guys are leading the plan to make OCaml without GC, then that would be a game changer. It would basically be like haskell without the GC. If that occurs, I'm joining and pulling out my old OCaml projects. Good Video (just for giving me the plan to make OCaml without GC).
@@giovannisolimeno5040 That's true. Regular programmers are not leaving rust. I should have said, "Some of us are second guessing using Rust as a main go to programming language (especially for embedded stuff and C++ replacement).
Eager vs. lazy, simple and powerful module system (still, I'd prefer SML), portable bytecode implementation and highly efficient native compilers for major platforms, quite a bit faster than GHC.
I've tried learning OCaml by making a Tic-Tac-Toe game in the terminal. And I quit the moment I learned that in order to mutate the matrix, I basically need to create a new one with the element changed. And such a function is not even a part of the standard library. I love functional features of Rust (immutability by default, iterators, enums, etc.) but I really don't think the language should prevent mutability when it just makes sense and is way more efficient. Still hoping we would get an actual "Rust with GC" type of language though
@@rallokkcaz Maybe I've overlooked it, but there was an SO thread saying this is the way to do it in OCaml. Can you link where I can read more about it?
@@TS-by9pg there's a few ways, like using a matrix of refs. And with the work they're doing at jane street on improving the type system, the copy-everything pattern should be possible to silently optimise to in-place mutation
haskell has great docs + hoogle and cabal is more than enough to get far. It is no more time consuming than what it is to learn ocaml, maybe easier because you commit to the functional way.
The problem about Haskell is Haskell always has the stink of it being a education only language. Like its the language that you get introduced to in a university programming language paradigms class when they teach fp. Why do you want to learn a language that not many companies are actually using to build stuff. Sure, u can learn a language purely for fun but it would better if there could be some return on investment on that right?
When I first looked at OCaml sometime last year, I got as far in the landing page as it said "OCaml is an Object Oriented language" and immediately closed the tab. Waste of my time.