Re:Why study functional programming? (2012)
by assbuttbuttass on Tuesday August 02, 2022 @03:12PM
(#32323016)
Most functional languages allow mutability when you need it, they just default to immutable data. Haskell might be the exception, where everything has to be immutable all the time
[ Parent
| on HN ]
Re:Why study functional programming? (2012)
by poorlyknit on Tuesday August 02, 2022 @03:55PM
(#32323494)
This is not true, Haskell of course allows you to mutate state. It just forces you to declare it: For example, there's a MutableByteArray type whose operations only work in a specific Monad (because Haskell...) [1].
There's also more basic stuff like IORef which represents an assignable variable [2]. Again, you're constrained to use this in IO contexts.
Etc.
Haskell basically just forces you to do that thing someone else in this thread mentioned: Write functional APIs, allow side effects but make them explicit and confined to very specific places.
[1]: https://hackage.haskell.org/package/primitive-0.7.4.0/docs/s... [2]: https://hackage.haskell.org/package/base-4.16.3.0/docs/Data-...
Re:Why study functional programming? (2012)
by marcosdumay on Tuesday August 02, 2022 @03:52PM
(#32323463)
Everything does not have to be immutable in Haskell. It's only that mutability can only exist in IO or some other context that deals with it. The language enforces purity, not immutability.