[Haskell-cafe] Re: monad subexpressions

Sebastian Sylvan sebastian.sylvan at gmail.com
Fri Aug 3 14:14:48 EDT 2007

On 03/08/07, apfelmus <apfelmus at quantentunnel.de> wrote:
> Chris Smith wrote:
> > Also, I got so frustrated that I ended up abandoning some code
> > recently because STM is, in the end, so darn hard to use as a
> > result of this issue. I'd love to see this solved, and I'm quite
> > eager to do it.
> This sounds suspicious, since the order of effects is of course
> important in the STM monad. Can you post an example of code you intend
> to abandon due to ugliness? I'd be astonished if there's no better way
> to write it.

Just because order *technically* matters doesn't mean it *actually*
matters in a given circumstance:

mytransaction = do {
  x0 <- readTVar xvar0
  x1 <- readTVar xvar1
  xn <- readTVar xvarn
  return $ foo x0 x1 .. xn


mytransaction = return $ foo $(readTVar xvar0) $(readTVar xvar1) ..
$(readTVar xvarn)

Now I'm not to happy about the long names for reading variables
either, short overloaded names like "get" and "put" would look much
nicer in this example, and in other places too. And certainly,
sometimes you do want to name things for convenience. But in *lots* of
cases you just want to e.g. read N variables, in an arbitrary order,
and then do something with them. Yes the order matters to the
*compiler*, but it doesn't always matter to the *programmer*, so to
have a more convenient way to express those cases would be very nice,
IMO. And there may even be cases where the order does matter but you'd
be happy with a left-to-right ordering.

This has been a pet-peeve of mine for ages. Imperative programming in
Haskell is neat, but I really don't want to write what amounts to
almost assembly programming levels of explicitness for simple tasks.

I'd also like to reiterate my request for a notation that doesn't
require brackets around the *action* but will also work by applying it
to a function which when fully applied to its argument returns an
action (i.e.:   $foo x y + $bar z w, rather than $(foo x y) + $(bar z
w)). Function application is normally very low-noise in Haskell
(good), and it would be nice if we can keep it low-noise in this
notation too.

Maybe $ isn't a good operator though.. How about #? Maybe using angle
brackets would work.. I'd still like to have them work for functions
returning actions though ( <foo> x y + <bar> z w ). Wonder what that
would do to ordering comparisons, lexically speaking....

Sebastian Sylvan
UIN: 44640862

More information about the Haskell-Cafe mailing list