
IMO, having <- in do syntax look like assignment is bad enough as it is, no need to further enforce the illusion. The variable shadowing that effectively occurs in that example is still just as bad as regular shadowing. On Wed, Aug 26, 2015 at 05:55:45PM +0530, Anupam Jain wrote:
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 _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe