[Haskell-cafe] "Assignment" in do blocks?
Anupam Jain
ajnsit at gmail.com
Wed Aug 26 12:25:45 UTC 2015
Hi all,
I'd like to propose an inbuilt "assignment" operator for use within do-blocks.
Here's a common pattern -
do
foo <- someaction
do something with foo
-- Here we "update" the value of foo
let foo' = bar foo
-- The code from this point onwards shouldn't use foo
-- but there is no way to enforce that
What I'd like to do instead is something like -
let foo = bar foo
But to Haskell this is a recursive definition instead of an update to
the previous value.
I can do this instead -
foo <- return $ bar foo
which works fine but (I assume) GHC currently can't optimise it for
arbitrary monads. Also it won't necessarily work if the monad laws
don't hold.
It would be nice to have an "assignment arrow", say (<-=), which lets
GHC optimise this, so -
foo <-= bar foo
...
desugars to something like -
foo' (bar foo)
where
foo' foo = ...
-- Anupam
More information about the Haskell-Cafe
mailing list