[HN Gopher] Functional Programming in OCaml
___________________________________________________________________
Functional Programming in OCaml
Author : noch
Score : 117 points
Date : 2021-07-27 14:32 UTC (8 hours ago)
(HTM) web link (www.cs.cornell.edu)
(TXT) w3m dump (www.cs.cornell.edu)
| bvrmn wrote:
| > 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 wrote:
| I 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.
| chmaynard wrote:
| 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.
| nanis wrote:
| >> 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").
| 2wrist wrote:
| There 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...
| Blikkentrekker wrote:
| So 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.
| zz865 wrote:
| This 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.
| masijo wrote:
| Too real.
| agumonkey wrote:
| I remember when coursera, stanford et al came.. I had
| subscription boulimia .. I only finished 50% of the one I
| attended.
| mkw2000 wrote:
| True story
| mkw2000 wrote:
| Sorry this made you upset
| yawaramin wrote:
| Duplicate of https://news.ycombinator.com/item?id=27966135
| Jtsummers wrote:
| By 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).
| zerr wrote:
| Any experiences teaching kids/students programming with FP?
| Starting with FP that is.
| eynsham wrote:
| The 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.
| dang wrote:
| Past threads related to this book:
|
| _Functional Programming in OCaml_ -
| https://news.ycombinator.com/item?id=22408664 - Feb 2020 (58
| comments)
|
| _Functional Programming in OCaml_ -
| https://news.ycombinator.com/item?id=22400233 - Feb 2020 (1
| comment)
|
| _Functional Programming in OCaml_ -
| https://news.ycombinator.com/item?id=19292067 - March 2019 (144
| comments)
| nanis wrote:
| Also this https://news.ycombinator.com/item?id=27966776 22
| Hours ago (2 comments)
| cepher wrote:
| This 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
|
| [1] https://www.nand2tetris.org/project06
| yawaramin wrote:
| Learning 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-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 ...
| yodsanklai wrote:
| > 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.
| Zababa wrote:
| Some 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.
| flowerlad wrote:
| The 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.
| qbit wrote:
| If you can find a copy, the first edition of 'Introduction to
| Functional Programming' by Richard Bird covers the concepts of
| functional programming in a language-agnostic way.
| yawaramin wrote:
| I don't think that would be helpful. If a book is too abstract
| it won't teach anything useful. Teaching something concrete is
| a good way to allow students to synthesize abstract ideas over
| time. And OCaml is a good vehicle for it because it has so much
| in common with other mainstream languages, especially nowadays
| with the trend towards functional/imperative/OOP mixed
| paradigms.
| adamwk wrote:
| > functors, monoids, monads, lazy evaluation
|
| These three things are mostly Haskell-specific though, at least
| in relation to functional programming.
| flowerlad wrote:
| Rust does lazy evaluation, and has functors, monoids and
| monads:
|
| https://docs.rs/functional/0.0.5/functional/trait.Functor.ht.
| ..
|
| https://docs.rs/functional/0.0.5/functional/trait.Monoid.htm.
| ..
|
| https://docs.rs/functional/0.0.5/functional/trait.Monad.html
| yawaramin wrote:
| Rust '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.
| pasabagi wrote:
| I don't think it's particularly out of the way. Iterators
| are a normal part of rust, and are lazy.
| grumpyprole wrote:
| There's nothing Haskell specific about those concepts. In
| fact, the first three where developed by mathematicians long
| before Haskell even existed.
| AnimalMuppet wrote:
| When mathematicians developed monads, they were doing
| abstract algebra. They were _not_ using them as a kludge to
| (for example) impose sequence on functional programming.
|
| _Having_ to use monads for sequencing is something that
| happens in Haskell and not in Rust.
| baby wrote:
| I'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/
| philzook wrote:
| I love it! Great job!
| Zababa wrote:
| Looking good! Is there a reason for why you use Core at some
| points?
| baby wrote:
| It 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 wrote:
| It 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).
| Zababa wrote:
| I didn't find any explanation other than it's well-
| accepted. That's true, however if it doesn't bring any new
| capabilities I think using just the standard library would
| make the tutorial more helpful and universal.
| [deleted]
| cjohnson318 wrote:
| I love that you started with opam, and not hello-world. More
| language guides should spend more time introducing tooling.
| amelius wrote:
| How is the new OCaml multicore support going? Any benchmarks yet
| which compare it to e.g. GoLang/Java/...?
| rbjorklin wrote:
| The 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.
| Zababa wrote:
| Multicore is coming along, you can read the latest news here:
| 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 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 but I
| haven't see any results from it.
| tyrotoxism wrote:
| As 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 wrote:
| +1,
|
| once you grok functors and algebraic type systems, a lot of
| other system design patterns seem like abstractions on a few
| key concepts.
___________________________________________________________________
(page generated 2021-07-27 23:01 UTC)