Hacker News new | ask | show | jobs
by rrgok 349 days ago
I don't understand why Haskell can't provide an imperative interface (at the grammar level, not semantic level) to get/set values in a type. If you can provide the do-notation to "simulate" imperative code, then why not?
2 comments

Haskell's design prioritizes referential transparency and equational reasoning, which would be compromised by imperative get/set operations that mutate state directly - lenses provide a purely functional alternative that maintains these properties.
That’s why I said at the grammar level and not at semantic level. I also brought the do-notation example, which kinda gives an imperative interface to the various monads
You get that on top of do notation, with no additional syntax required for example `IORef` or Bluefin's `State`:

https://www.stackage.org/haddock/lts-23.27/base-4.19.2.0/Dat...

https://hackage-content.haskell.org/package/bluefin-0.0.16.0...