4 ms·
> Haskell, Scala, F#, OCaml, etc. Rust is the first not-weirdass-academic-wtf language to have these features ;) (I love functional programming and apply the
by Shish2k 3y ago
> Haskell, Scala, F#, OCaml, etc.
Rust is the first not-weirdass-academic-wtf language to have these features ;)
(I love functional programming and apply the functional approach no matter what language I’m using - but why is it that functional languages are always so deeply down the academic rabbithole that they think eg “car” and "cdr” are intuitive names for “retrieve the first element of a list” and “retrieve the rest of the list” functions??)
- crvdgc 3y agoI'm sure you know car and cdr are named for historic reasons and they are not featured in ML family languages as listed above. But coming back to the name of "sum type", I find it very potent to be used with "product type" to reason about Algebraic Data Type's properties, like a * (b + c) = a * b + a * c and don't understand why it's often avoided to be called in this way in "mainstream" programming languages.
- aeonik 3y ago`car` (Contents of Address part of Register) and `cdr` (Contents of Decrement part of Register) are historical terms from the IBM 704, used in LISP. They're legacy from early computing, not academic jargon.
- kazinator 3y agoMacCarthy transformed them into academic jargon in fact. Knowing that the words originated in the IBM 704 idiosyncrasies not found in other machines, he used them anyway in papers about symbolic computation. Lisp pairs are flexible objects that can be coupled together into shapes and uses that are not lists. car and cdr can mean first and rest, and ANSI Common Lisp [1994] has those synonyms, but there are uses of cons cells where first and rest do not make sense. MacCarthy must have realized that words that do not invoke any connotations are good for the elements of a flexible pair structure. Choices like first/rest, left/right, top/bottom and others are saddled with semantics that don't match every use. Programs that need a pair structure in which the two pieces have very specific roles can provide their own synonyms, if their authors feel it makes code more readable. I seem to recall that Knuth, in TAOCP, at one point, calls the pointers of a binary tree node ALINK and BLINK.
- hurril 3y agoExcept Haskell, Scala and F#. They are neither academic nor rabbitholes. You're simply not familiar with them - perhaps a trip outside of your safe space could be something? :) Car and crd is lisp and from the 60:ies, basically. You can liken them to assembly instructions because that's kinda sorta why they're named like that. I still stand by what I said about them. If you write Rust for 1-2 years, I bet you you'll come to look at programming in those languages completely differently. I have a very high carry over, going in to Rust from those languages.
- xboxnolifes 3y agocar and cdr are no more confusing then the historical C functions that turn entire sentences into initialisms. And surely nobody would call C an academic language in this context.
- da39a3ee 3y agoTo be fair though, Scala's sum types are a bit of a hack aren't they, or at least pretty cumbersome? Declaring a `sealed abstract class` (or is it trait) and then a bunch of case classes syntactically disconnected from the sealed abstract thing that defines the sum type.
- sc22 3y agoScala 3 has enums, which can also serve as ADts: https://docs.scala-lang.org/scala3/reference/enums/enums.html https://docs.scala-lang.org/scala3/reference/enums/enums.htm...
- da39a3ee 3y agoAh right, thanks. I've only used Scala 2. To what extent do Scala 3 enums give you what you want in the way of sum types? E.g. compared to Rust enums?