Type Classes

Type Classes

Share this post

Type Classes
Type Classes
Elephant variable reassignment

Elephant variable reassignment

An example using the (.=) operator from microlens-mtl to write Haskell code that resembles reassignment of mutable variables.

Chris Martin's avatar
Chris Martin
Aug 27, 2017
∙ Paid
1

Share this post

Type Classes
Type Classes
Elephant variable reassignment
Share

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.

Already a paid subscriber? Sign in
© 2025 Mission Valley Software LLC
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share