Skip to content

chris-martin/elephant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

elephant

This demo project 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

function 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.

This project provides the long answer, demonstrating how to use a lens and the state monad to produce something that looks like a direct translation of the imperative-programming concept of reassigning a variable.

We end up writing a program that looks like this:

do
  printElephant
  setElephant 2
  printElephant

When the value of elephant is initialized as zero, this program prints 0 and then 2.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published