Live data from Hacker News

Learn Programming with OCaml

usr.lmf.cnrs.fr

111–120 of 150 posts

Re: Learn Programming with OCaml

#111

Earlier quoted context omitted.

An ML is great for the theory or abstraction side of programming, but C is also hands down the best language to get a sense of how the computer is running your program. It’s still an abstraction, but at least being aware of memory management, copying vs referencing, etc are hugely important concepts that ML languages can hide.

> but C is also hands down the best language to get a sense of how the computer is running your program. C is in an odd position right now to argue it is how the machine is really working. Computers are more complicated since bigger caches entered the picture. Hell I do not think even ASM is a good approximation on how machine really work given the data dependencies will make stuff being processed in parallel instead…

> an imperative language procedural language with a clean mapping to ASM

C really isn't as great for this as is often suggested either, not for decades at least

K&R's original compiler on an actual Digital machine from that era makes the case best, but remember this is the era when if you hot loop over modifying a variable your compiler is going to emit memory stores for each iteration - because that's what you wrote, isn't it? No modern C compiler would do this because it's awfully slow.

Likewise that iteration of C doesn't have what you'd recognise as function prototypes, it doesn't care whether your function takes six arguments, here are six arguments the first two are integers, good luck with that. In assembler that makes sense, but you don't do that in modern C either.

C is still a close-to-the-metal language, but it is programming an abstract machine and it is important that the programmer knows that's not really how the machine works, if you want to learn about the machine you will need to write at least assembler and possibly just go learn electronics. Good luck.

Re: Learn Programming with OCaml

#112

I believe that an ML should be the First Language for Computer Scientists. It's much less clear which language we should teach people for whom it will likely be their Only Language, today Python is common, and for fields which care about stats often R is used, I've also seen Java used in this role. But for a First Language specifically I am in no doubt that an ML should be chosen, and this is despite the fact that th…

An ML is great for the theory or abstraction side of programming, but C is also hands down the best language to get a sense of how the computer is running your program. It’s still an abstraction, but at least being aware of memory management, copying vs referencing, etc are hugely important concepts that ML languages can hide.

> C

Well some procedural language would do the trick.

The main issue is see is people jumping straight into OO or functional programming and developing a habit of over-abstracting everything.

I think something like Odin which is purely procedural but has less historical cruft and offers modern affordances would be a great choice.

C is absolutely worth learning but students will spent a lot of time learning to cope with its sharp corners and subpar standard library. Some might give up before they discover the joys for programming.

Re: Learn Programming with OCaml

#114
post #94

Earlier quoted context omitted.

>use the small windows of time we look at our phone again, it's not a small window. It's six hours. That's almost half your waking day. People spend virtually their entire leisure time rotting away on low quality entertainment. >will me spending my time learning OCaml help me land that job that's a pointless question for one you never know if something will land you a job, new opportunities don't open up before you d…

“Low quality entertainment” is a very elitist thing to say. Most don’t have time or luxury of even being introduced ( via an east coast liberal arts college ) to read Tolstoy or appreciate the finer motions of Tchaikovsky. Instead the Druski memes will do just fine, mixed in with the AI slop. Or maybe they’re physically or physiologically incapable of enjoying the outdoors or sport. Point is, my gen played strategy g…

Many of the classics were very popular and got their label later. Classics and pop culture are not necessarily at odds.

Re: Learn Programming with OCaml

#115

Earlier quoted context omitted.

> but C is also hands down the best language to get a sense of how the computer is running your program. C is in an odd position right now to argue it is how the machine is really working. Computers are more complicated since bigger caches entered the picture. Hell I do not think even ASM is a good approximation on how machine really work given the data dependencies will make stuff being processed in parallel instead…

> an imperative language procedural language with a clean mapping to ASM C really isn't as great for this as is often suggested either, not for decades at least K&R's original compiler on an actual Digital machine from that era makes the case best, but remember this is the era when if you hot loop over modifying a variable your compiler is going to emit memory stores for each iteration - because that's what you wrote…

> C really isn't as great for this as is often suggested either, not for decades at least

It's good enough for undergraduate teaching. In C, you can easily explain the relation between a struct definition and its layout in memory. It's much more difficult in Caml (what's the relation between an algebraic datatype and its layout in memory?) or Java (which introduces pointers that you never asked for).

We (University of Paris-Cité) are teaching Java in first year, then C and Caml in second year, with seemingly good results.

Re: Learn Programming with OCaml

#116
post #102

Earlier quoted context omitted.

I think this PDP-11 meme is quite misleading. There is nothing really in the C programming model specific to the PDP-11 and C was used on systems much weirder than a PDP-11. C is also very successfully the basis of many parallel programs running on multi-processor systems with a memory model in the standard that was created much later than the PDP-11. Also somehow the implied argument that computing hardware and oper…

It's clear that the authors were either inspired by the PDP-11 ISA and/or designed the language to make porting UNIX from PDP-11 Assm to it easier. UNIX for PDP-7 in Assm -> UNIX for PDP-11 in Assm -> UNIX for PDP-11 in C https://news.ycombinator.com/item?id=42644851 and https://news.ycombinator.com/item?id=43245166

I do not think that pre- and postincrement operator being inspired by PDP-11 has anything to with fundamental system design questions.

Re: Learn Programming with OCaml

#117

I believe that an ML should be the First Language for Computer Scientists. It's much less clear which language we should teach people for whom it will likely be their Only Language, today Python is common, and for fields which care about stats often R is used, I've also seen Java used in this role. But for a First Language specifically I am in no doubt that an ML should be chosen, and this is despite the fact that th…

An ML is great for the theory or abstraction side of programming, but C is also hands down the best language to get a sense of how the computer is running your program. It’s still an abstraction, but at least being aware of memory management, copying vs referencing, etc are hugely important concepts that ML languages can hide.

Maybe learn Rust as a middle ground between ML and C, then? It has sum types like ML and teaches you memory management like C.

Re: Learn Programming with OCaml

#118

Earlier quoted context omitted.

Yes I contributed code to a paper on it this spring. It’s hard to measure and “studying” it just means feeding money into frontier models. If anyone has a few billion tokens for a couple masters students hmu so they can get it published.

Can it not be studied with open weight models? This is a genuinely curious question, not an attempt at scoring a point.

I don’t know it’s not my paper. I don’t want to talk shit but I’m also a little confused at this apparent limitation.

Re: Learn Programming with OCaml

#119
This book is a great.

A common misunderstanding around OCaml is to classify it as a functional programming language, it is actually a multi-paradigm language. In short, in OCaml, you can write in any paradigm you want, imperative, object, or functional.

Typically, I write in a mix of OCaml and stubs in C (for bindings to Linux libraries), for everything, to replace shell scripts, Python scripts, Javascript/Typescript, but also for big applications (I wrote a clone of Emacs in OCaml, a long time ago, before writing MLdonkey).

Once you have started using it, it does not replace your main programming languages, it replaces all the languages you needed...

Re: Learn Programming with OCaml

#120
post #116

Earlier quoted context omitted.

It's clear that the authors were either inspired by the PDP-11 ISA and/or designed the language to make porting UNIX from PDP-11 Assm to it easier. UNIX for PDP-7 in Assm -> UNIX for PDP-11 in Assm -> UNIX for PDP-11 in C https://news.ycombinator.com/item?id=42644851 and https://news.ycombinator.com/item?id=43245166

I do not think that pre- and postincrement operator being inspired by PDP-11 has anything to with fundamental system design questions.

> Q. How do you port an OS from one language to a new one, pre-LLM?

A. you reduce impedance mismatch, but making the new language using similar concepts and mechanisms

--

You're right, this table is just a coincidence, probably derived from the standard math notation, and used in many PLs like FORTRAN and Python ;)

  PDP-11        C
  
  INC R         ++i
  DEC R         --i
  ADD src, dst  dst += src
  SUB src, dst  dst -= src

  (R)+          *p++
  -(R)          *--p
  X(R)          p[x]
  @(R)+         **pp++
  @X(R)         *p[x]

  BR label      goto label  ; near jump
  JMP label     goto label  ; far jump
Post reply on HN