12 ms·
Functional Programming in OCaml
- chmaynard 5y agoApparently CS 3110 (Spring 2021) was only offered to students enrolled at Cornell. If true, why is this website of interest to HN readers? Just asking.
- nanis 5y ago>> Apparently CS 3110 (Spring 2021) was only offered to students enrolled at Cornell. If true, why is this website of interest to HN readers? Just asking. Note the following: > This work is based on over 20 years worth of course notes and intellectual contributions by the authors named above; teasing out who contributed what is, by now, not an easy task. The primary compiler and author of this work in its form as a unified textbook is Michael R. Clarkson. You do not need to be enrolled in CS 3110 to be able to utilize this content (said "unified textbook").
- zz865 5y agoThis looks great. I'll add it to my list of 100 MOOCs I'd love to do but realistically will never get past the first session.
- 2wrist 5y agoThere is a video playlist by Michael Clarkson which has been released recently too. He is a pretty good communicator! https://www.youtube.com/playlist?list=PLre5AT9JnKShBOPeuiD9b-I4XROIJhkIU https://www.youtube.com/playlist?list=PLre5AT9JnKShBOPeuiD9b...
- baby 5y agoI’ve been working on an OCaml by example page. It’s not really ready for prime time but you can at least learn the basics with it and hell, even contribute if you want :) https://o1-labs.github.io/ocamlbyexample/ https://o1-labs.github.io/ocamlbyexample/
- Zababa 5y agoLooking good! Is there a reason for why you use Core at some points?
- baby 5y agoIt seems like a lot of people use Core instead of the stdlib, so much that I felt like it was best practice to do that. I explain that in the first sections.
- johnisgood 5y agoIt would be nice if it had examples without Core, too, using only OCaml's standard library. I would like to stick to the standard library first, and if it is not enough, then maybe OCaml Batteries or Core. Perhaps give a reference to "libraries" on the first page (or all?) where you use Core so people know how to use Core (opam, dune).
- baby 5y agoYeah that makes sense, I think it might be a good idea to teach with the stdlib.
- yawaramin 5y agoI've written a condensed intro without Jane Street libraries: https://dev.to/yawaramin/practical-ocaml-314j https://dev.to/yawaramin/practical-ocaml-314j
- johnisgood 5y ago
- Blikkentrekker 5y agoSo from what I understand from this the objective is to teach a “vastly different perspective” and thereby improve one's programming productivity by idealistically a factor four, by being forced into a new way of thinking? They could have certainly done something more radical than OCaml then such as, say, Idris2 which is truly a challenge for those not used to it.
- flowerlad 5y agoThe intro page says this course is not about OCaml, but then the remaining pages go into detail about the various features of OCaml. The problem with this approach is that when you read about a feature, you don't know if it is a OCaml-specific thing or whether it is a general functional programming concept. I would like to see a course or textbook that explains functional programming in the abstract. Instead of going into the details of any one functional language, gives examples of how various functional languages implement the various core ideas of functional programming. So, explain functional programming concepts such as pure functions, referential transparency, functors, monoids, monads, effects, lazy evaluation and so on, not in the context of any specific language, but giving examples from multiple functional languages. In other words, focus on functional programming in general, instead of one specific implementation of it. I have been looking for such a textbook or course, but it doesn't exist.
- adamwk 5y ago> functors, monoids, monads, lazy evaluation These three things are mostly Haskell-specific though, at least in relation to functional programming.
- flowerlad 5y agoRust does lazy evaluation, and has functors, monoids and monads: https://docs.rs/functional/0.0.5/functional/trait.Functor.html https://docs.rs/functional/0.0.5/functional/trait.Functor.ht... https://docs.rs/functional/0.0.5/functional/trait.Monoid.html https://docs.rs/functional/0.0.5/functional/trait.Monoid.htm... https://docs.rs/functional/0.0.5/functional/trait.Monad.html https://docs.rs/functional/0.0.5/functional/trait.Monad.html
- yawaramin 5y agoRust 'does' lazy evaluation only in the sense that you can implement it if you go out of your way. It's not the default like in Haskell. It's not a functional programming language–having functors, monoids, and monads (in some restricted sense) doesn't make a language FP.
- cepher 5y agoThis book was my introduction to OCaml, and I followed it concurrently with the Nand2Tetris course. Project 6 of Nand2Tetris [1] has you write an assembler for their hack computer, and OCaml seemed like a perfect fit. Chapter 10 of this book introduces you to parsing and lexing, and it was really fun following along while writing the hack assembler. Here's an implementation for those interested: https://github.com/senhorsolar/hack-assembler https://github.com/senhorsolar/hack-assembler [1] https://www.nand2tetris.org/project06 https://www.nand2tetris.org/project06
- yawaramin 5y agoDuplicate of https://news.ycombinator.com/item?id=27966135 https://news.ycombinator.com/item?id=27966135
- Jtsummers 5y agoBy the same submitter. The mods probably asked them to resubmit it, they do that with interesting submissions that don't gain traction (poor timing usually).
- yawaramin 5y agoLearning OCaml will teach you the languages and concepts of the next 5 to 10 years of mainstream programming languages. E.g., here's a TC39 proposal to add declarations to conditionals: https://github.com/tc39/proposal-Declarations-in-Conditionals https://github.com/tc39/proposal-Declarations-in-Conditional... It says, in the 'Future Work' section: > This could be extended to allowing multiple names to be initialized (such as through destructuring) with a "normal" conditional to be written after the assignment with a ; (similar to a for). if (let x = 1, y = 2; x || y) { /* ... */ } if (let {x, y} = data; x && y) { /* ... */ } Meanwhile, OCaml from day one: if let x = true in let y = true in x || y then ... if let { x; y } = data in x && y then ...
- Zababa 5y agoSome other examples: immutable records and tuples in JS, records in Java and C#; pattern matching in Java and C#, stage 1 in JS; algebraic data types with sealed classes coming in Java, and used a lot in Rust.
- yodsanklai 5y ago> Learning OCaml will teach you the languages and concepts of the next 5 to 10 years of mainstream programming languages I think this assertion was true 20-25 years ago. Less so now.
- kupopuffs 5y agoAgree. Some did it better, but languages have caught up. Even the C you learned in school has evolved
- yawaramin 5y agoEvolution comes at great cost though. Languages have to find ways to add new functionality while preserving backward compatibility. And the cost is great in human terms as well. Python added a walrus operator after so much fighting that Guido van Rossum decided to resign as BDFL. Meanwhile, OCaml doesn't even need an explicit new feature for that, because it's expression-oriented from day one. Not to forget that when languages pile on features over the course of years, they effectively split their users into 'old-style' and 'new-style' codebases, where people need to worry about what features are usable with what versions of the language. It's a huge mess.
- bvrmn 5y ago> This course is about making you a better programmer. It is a very bold statement. There is nothing in course about how to fight complexity. Knowledge how to traverse an ADT tree helps a little unfortunately. But it is a great classic CS course though.
- yodsanklai 5y agoI agree. It's certainly beneficial to know different paradigms but it's not the end of the story. There are OCaml codebases out there which are pretty messy.
- uncomputation 5y agoTo be fair, it doesn’t say that it will make a perfect programmer, but surely knowing about functional programming and ideas won’t hurt.
- yawaramin 5y ago> There is nothing in course about how to fight complexity. You should read it more carefully. E.g. https://www.cs.cornell.edu/courses/cs3110/2020sp/textbook/modules/intro.html https://www.cs.cornell.edu/courses/cs3110/2020sp/textbook/mo... > One key solution to managing complexity of large software is modular programming: the code is composed of many different code modules that are developed separately. This allows different developers to take on discrete pieces of the system and design and implement them without having to understand all the rest. But to build large programs out of modules effectively, we need to be able to write modules that we can convince ourselves are correct in isolation from the rest of the program. Rather than have to think about every other part of the program when developing a code module, we need to be able to use local reasoning: that is, reasoning about just the module and the contract it needs to satisfy with respect to the rest of the program. If everyone has done their job, separately developed code modules can be plugged together to form a working program without every developer needing to understand everything done by every other developer in the team. This is the key idea of modular programming.
- rawoke083600 5y agoI think the "better" is a secondary effect. Imagine you are a UFC fighter and going to the gym and lift weights to be a "better fighter" even though, you didn't throw one-kick or punch one bag etc :P
- amelius 5y agoHow is the new OCaml multicore support going? Any benchmarks yet which compare it to e.g. GoLang/Java/...?
- Zababa 5y agoMulticore is coming along, you can read the latest news here: https://discuss.ocaml.org/t/multicore-ocaml-june-2021/8134 https://discuss.ocaml.org/t/multicore-ocaml-june-2021/8134 In terms of performance, there is this paper https://kcsrk.info/papers/system_effects_feb_18.pdf https://kcsrk.info/papers/system_effects_feb_18.pdf where on a single core async OCaml and effect OCaml are close to Go's net/http, and there is also this project https://github.com/ocaml-multicore/retro-httpaf-bench https://github.com/ocaml-multicore/retro-httpaf-bench but I haven't see any results from it.
- rbjorklin 5y agoThe last multicore prerequisite will land with 4.13 in September. My understanding is that the next release after that due in Q1 of 2022 will have multicore support.
- pjmlp 5y agoIt is coming along, however in the age of security and distributed computing, what most applications really want are multiple processes with OS IPC anyway.
- tyrotoxism 5y agoAs a veteran of this class, I do believe it helped make me a better programmer. There's a noticeable divide in terms of programming confidence/flexibility/efficiency among the Cornell CS students who do well in this class and enjoy it, and those who fear it or runaway from it. That said, a lot of the benefit came from this course gathering the brightest CS students as TAs. Without having access to those TAs and the challenges they posed in section or office hours, I'm not sure it has nearly as much value.
- 0xB31B1B 5y ago+1, once you grok functors and algebraic type systems, a lot of other system design patterns seem like abstractions on a few key concepts.
- zerr 5y agoAny experiences teaching kids/students programming with FP? Starting with FP that is.
- eynsham 5y agoThe first programming course at Oxford is FP. It makes some sense: (1) sometimes diving into something helps (especially with support from tutors) (2) it gives those with existing programming knowledge something new to work with and (3) functional programming concepts are generally helpful, so it’s still useful in other spheres.
- epolanski 5y agoSICP focuses on Lisp/Scheme and it's one of the best programming books for beginners I can think of.
- yawaramin 5y agoTwo that I can think of: - Bootstrap teaches a toned-down version of Racket (i.e. Scheme): https://bootstrapworld.org/materials/spring2021/en-us/courses/hour-of-code/ https://bootstrapworld.org/materials/spring2021/en-us/course... . It's taught in some schools as well as a comp sci curriculum. - https://code.world/ https://code.world/ teaches using a toned-down version of Haskell. To my knowledge it's not used in schools.
- schot 5y agoThe Coursera course Programming Languages (Part A and B) by Dan Grossman teaches FP (and more) using SML and Racket. I enjoyed this course a lot. I would not recommend it for kids, but it should be great for students with some limited programming experience. [1]: https://www.coursera.org/learn/programming-languages https://www.coursera.org/learn/programming-languages [2]: https://www.coursera.org/learn/programming-languages-part-b https://www.coursera.org/learn/programming-languages-part-b
- dang 5y agoPast threads related to this book: Functional Programming in OCaml - https://news.ycombinator.com/item?id=22408664 https://news.ycombinator.com/item?id=22408664 - Feb 2020 (58 comments) Functional Programming in OCaml - https://news.ycombinator.com/item?id=22400233 https://news.ycombinator.com/item?id=22400233 - Feb 2020 (1 comment) Functional Programming in OCaml - https://news.ycombinator.com/item?id=19292067 https://news.ycombinator.com/item?id=19292067 - March 2019 (144 comments)
- nanis 5y agoAlso this https://news.ycombinator.com/item?id=27966776 https://news.ycombinator.com/item?id=27966776 22 Hours ago (2 comments)
- ttymck 5y ago(Inspired by this post,) I gave the official ocaml tutorial a whirl. I quite enjoyed the syntax, and the easy install (of opam). However, I thought I should mention that I got _exactly_ as far as [0] (found while trying to google a solution) before giving up. The REPL is great, but if I can't compile easily, it doesn't inspire the confidence needed to go any further. [0] https://news.ycombinator.com/item?id=7418543 https://news.ycombinator.com/item?id=7418543
- WastingMyTime89 5y ago[0] is a post from seven years ago where the poster installed ocaml using the Debian package manager rather than through opam as recommended and failed to use a core library because they didn't understand the admittedly strange way Debian packages Ocaml. You probably shouldn't use Debian packages for Ocaml (nor for anything else admittedly - Debian has terrible habits regarding patching and splitting). The community actually standardized its way of compiling around Dune which is very good.
- ttymck 5y agoYes, it was uncanny that I was led to a seven year old post, trying to follow the currently available "a first hour with ocaml" tutorial [1] [1] https://ocaml.org/learn/tutorials/a_first_hour_with_ocaml.html https://ocaml.org/learn/tutorials/a_first_hour_with_ocaml.ht...
- Zababa 5y agoThere is a relatively new page to install OCaml that works really well (on Linux at least) https://ocaml.org/learn/tutorials/up_and_running.html https://ocaml.org/learn/tutorials/up_and_running.html. As the sibling mentionned, compiling is mostly done through dune https://github.com/ocaml/dune https://github.com/ocaml/dune
- ttymck 5y agoIt appears I unwittingly skipped a step, misled by the title "a first hour with ocaml" [1]. Thanks for the tip on dune. [1] https://ocaml.org/learn/tutorials/a_first_hour_with_ocaml.html https://ocaml.org/learn/tutorials/a_first_hour_with_ocaml.ht...
- systems 5y agoIf you want to learn OCaml, you should probably check https://dev.realworldocaml.org/ https://dev.realworldocaml.org/ (free to read online) It is co authored by Yaron Minsky, I think Yaron plays a big role in making OCaml relevant I think OCaml would have been a far less popular language, had Yaron chosen another language for jane street
- yawaramin 5y agoIMHO, the OP book is a better choice for learning as it explains FP and OCaml's implementation of it from the ground up, and doesn't rely on Jane Street libraries.