Elephant variable reassignment
An example using the (.=) operator from microlens-mtl to write Haskell code that resembles reassignment of mutable variables.
This demonstration was inspired by a Stack Overflow question which asks:
How can I re-assign a variable in a function in Haskell?
For example,
elephant = 0 setElephant x = elephant = x
The short answer is that we don't have a language-level mechanism to model that sort of thing in Haskell, and it's generally not what you want anyway.
Here I give a long an…
Keep reading with a 7-day free trial
Subscribe to Type Classes to keep reading this post and get 7 days of free access to the full post archives.