
Another alternative (which I got from Greg Morrisett) that I'm toying with is this. It's tiresome to write
do { x <- <stuff1>
; y <- <sutff2>
; f x y }
In ML I'd write simply
f <stuff1> <stuff2>
So Greg's idea (or at least my understanding thereof) is to write it like this:
do { f $(stuff1) $(stuff2) }
The idea is that a "splice" $e must be lexically enclosed by a 'do', with no intervening lambda. It's desugared to the code above; that is, each splice it pulled out, in lexically left-right order, and given a name, which replaces the splice.
Of course it doesn't have to look like the above; the rule applies to any do:
do { v <- this; foo $(h v); y <- f $(t v v); ...etc }
The "linearise the splices" rule is quite general.
Don't burn any cycles on concrete syntax; I know the $ notation is used for Template Haskell; one would need to think of a good syntax. But the idea is to make it more convenient to write programs that make effectful calls, and then use the result exactly once.
Anyway, this'd do what the original proposer wanted, but in a much more general way.
Just a thought -- I have not implemented this.
Simon
| -----Original Message-----
| From: haskell-prime-bounces@haskell.org [mailto:haskell-prime-bounces@haskell.org] On Behalf Of Adde
| Sent: 10 July 2007 21:40
| To: kahl@cas.mcmaster.ca
| Cc: haskell-prime@haskell.org
| Subject: Re: Make it possible to evaluate monadic actions when assigning record fields
|
| On Tue, 2007-07-10 at 17:04 +0000, kahl@cas.mcmaster.ca wrote:
| > Isaac Dupree