News for hackers. Stuff that matters.
Re:Which Programming Languages Are Functional? by seanwilson on Wednesday December 30, 2015 @10:42AM (#10812460)
I was more referring to how OCaml allows mutable references and arrays, and allows IO similar to imperative languages whereas Haskell isn't so generous.
Re:Which Programming Languages Are Functional? by mightybyte on Wednesday December 30, 2015 @04:05PM (#10814361)
Haskell absolutely allows mutable references and arrays. See IORef [1] and MVector [2]. Notice how the functions that perform mutation are monadic. That's Haskell controlling the side effects and making sure that they don't pollute pure code. The ST monad stuff [3] that wyager mentioned is even cooler because it allows you to bundle up side effecting stuff and actually use it in pure code in a completely safe way, which is something that you can't do (without the dubious usafePerformIO) with the IO monad.

[1] https://downloads.haskell.org/~ghc/latest/docs/html/librarie...

[2] http://hackage.haskell.org/package/vector-0.11.0.0/docs/Data...

[3] https://downloads.haskell.org/~ghc/latest/docs/html/librarie...

Re:Which Programming Languages Are Functional? by wyager on Wednesday December 30, 2015 @12:28PM (#10813111)
Haskell actually does allow mutability in pure code using the ST monad.

It's pretty cool; you can use ST to have mutable variables and arrays and such, but the mutable values aren't allowed to escape the ST "context". So you're still guaranteed immutability outside of the ST monad, because the type system locks all mutable values inside the monad.

This is mostly only used in very-high-performance libraries that use algorithms based on array access.