4 ms·
Haskell's core data structures are immutable (ADTs, tuples, records, etc.) -- what do you mean?
by cyrus_ 16y ago
Haskell's core data structures are immutable (ADTs, tuples, records, etc.) -- what do you mean?
- jmillikin 16y agoI'm assuming anything in the "base" library counts as core; in it, you have pointer/buffer manipulation (Foreign.* ), synchronized mutable containers (Control.Concurrent.* ), ST (Control.Monad.ST), and various mutable containers (IORef, STRef, HashTable). It's true that Haskell has many immutable types, but that's true of almost any language. Haskell is no more immutable than Java or C#, and certainly nothing like truly immutable languages such as Coq or Agda.
- gwern 16y agoStuff in the sinbin (or the 'IO monad') are definitely second-class citizens in the language and community. And not all of those examples are mutable - the whole point of ST is that it's safe for it to be implemented using mutation while still being treated as having immutable semantics, this doesn't mean the compiler or library actually use mutation in ST code.
- jmillikin 16y ago> Stuff in the sinbin (or the 'IO monad') are definitely second-class citizens in the language and community. [citation needed] I've never noticed any particular dislike for IO in the language or community, excepting cases where it was obviously not appropriate. A general feeling that IO is best minimized is common throughout all languages and experienced communities. > the whole point of ST is that it's safe for it to be implemented using mutation while still being treated as having immutable semantics, this doesn't mean the compiler or library actually use mutation in ST code. I disagree; ST would be practically useless if it could not be relied upon to use mutation. Its purpose is to signal "this code uses safe mutation", not "this code is immutable * wink* * wink* "
- gwern 16y ago> I've never noticed any particular dislike for IO in the language or community, excepting cases where it was obviously not appropriate. And that isn't enough? 'Use IO only where you must' is not second-class? In any other context, I would definitely see that as second-classness - 'Oh, I only employ black workers when I simply can't get any white workers and must employ them'. IO is first-class only in the restricted and technical sense that yes, the type system will let you pass around IO values and functions. > I disagree; ST would be practically useless if it could not be relied upon to use mutation. But it still acts immutable and for all we know, is immutable. Just because some compilers and libraries use mutation doesn't prove your thesis that Haskell is as mutation happy as something like Java. As Isaac Asimov said, the man who thinks the Earth is a perfect sphere is wrong, like the man who thought it flat, but if you think he was just as wrong as the flat-Earther, you're more wrong than them both.
- jmillikin 16y ago> And that isn't enough? 'Use IO only where you must' is not second-class? In any other context, I would definitely see that as second-classness In that case, IO is second class in most languages, including Python, Ruby, C#, Java, C++, and C. I do not consider any of them to be functional. > But it still acts immutable and for all we know, is immutable. Just because some compilers and libraries use mutation doesn't prove your thesis that Haskell is as mutation happy as something like Java. No, it doesn't "act immutable"; an ST that acted immutable would be equivalent to State. The only advantage of ST over State is that compilers implement it as a special case of IO, and thus it can be used in place of IO for known-pure mutations.
- shadowfox 16y agoOCaml has first class mutability and is usually considered a functional language (I am sure you can argue that of course).
- cyrus_ 16y agoLet me clarify that a bit further -- I'm not excluding languages which offer mutable data structures, even in standard libraries. I'm simply excluding languages where the use of these data structures are de-emphasized. This isn't a precise scientific definition of a functional language, but one that seems to quite cleanly differentiate languages like Haskell and ML from languages like Javascript and C#, all of which have first-class functions.
- dfox 16y agoYour definition also clearly differentiate between "Common Lisp as is taught on universities" and "Common Lisp as it's actually used", which might or might not be a good sign.