[Haskell-cafe] Re: monad subexpressions

2007-08-08 Thread apfelmus
Bulat Ziganshin wrote: apfelmus wrote: avoid the small layer of imperative code, of course. But the more you treat imperative code as somewhat pure, the greater the danger that the purely functional logic will be buried inside a mess of imperative code. In other words, the goal is exactly to

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-08 Thread Bulat Ziganshin
Hello apfelmus, Wednesday, August 8, 2007, 11:33:41 AM, you wrote: it's point of view of theoretical purist. i consider Haskell as language for real world apps and need to write imperative code appears independently of our wishes. in paricular, it's required to write very efficient code, to

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-05 Thread Bertram Felgenhauer
Bulat Ziganshin wrote: Hello apfelmus, Saturday, August 4, 2007, 12:18:33 PM, you wrote: Then, mytransaction reads mytransaction = return foo `apT` xvar0 `apT` xvar1 `apT` ... how about a+b*(c+d)? That follows the same pattern, return (+) `apT` a `apT` (return (*)

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-05 Thread ok
On 4 Aug 2007, at 12:41 am, Mirko Rahn wrote: rewrite *p++=*q++ in haskell? it's one of C idioms. probably, you don't have enough C experience to understand it :) Maybe, but how can *you* understand it, when the standard is vague about it? It could be A: *p=*q; p+=1; q+=1; B:

[Haskell-cafe] Re: monad subexpressions

2007-08-05 Thread Brian Hulley
On Fri Aug 3 06:06:31 EDT Neil Mitchell wrote: What are the semantics of do b f (- a) where does the evaluation of a get lifted to? I suggest the execution of (a) should be done immediately before the action obtained by applying the monadic function whose argument it is part of:

[Haskell-cafe] Re: monad subexpressions

2007-08-04 Thread apfelmus
Sebastian Sylvan wrote: Claus Reinke wrote: mytransaction = do { x0 - readTVar xvar0 x1 - readTVar xvar1 : xn - readTVar xvarn return $ foo x0 x1 .. xn } ah, a concrete example. but isn't that the typical use case for ap? mytransaction = foo `liftM` r xvar0 `ap` r xvar1 ..

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-04 Thread Bulat Ziganshin
Hello apfelmus, Saturday, August 4, 2007, 12:18:33 PM, you wrote: Then, mytransaction reads mytransaction = return foo `apT` xvar0 `apT` xvar1 `apT` ... how about a+b*(c+d)? -- Best regards, Bulatmailto:[EMAIL PROTECTED]

Re: Re[4]: [Haskell-cafe] Re: monad subexpressions

2007-08-04 Thread Claus Reinke
can you give translation you mean? i don't have anything against combinators, they just need to be easy to use, don't forcing me to think where i should put one, as i don't think with lazy code and C imperative code. and they shouldn't clatter the code, too. just try to write complex expression

Re[6]: [Haskell-cafe] Re: monad subexpressions

2007-08-04 Thread Bulat Ziganshin
Hello Claus, Saturday, August 4, 2007, 3:06:11 PM, you wrote: can you give translation you mean? i don't have anything against combinators, they just need to be easy to use, don't forcing me to think where i should put one, as i don't think with lazy code and C imperative code. and they

Re: Re[8]: [Haskell-cafe] Re: monad subexpressions

2007-08-04 Thread Brandon S. Allbery KF8NH
On Aug 4, 2007, at 11:19 , Bulat Ziganshin wrote: and use it. want to assign a=b/(c+d)? nothing can be easier! just define one more macro! And? Everything above machine code is just macros at various levels of abstraction, including all our favorite higher-level abstractions. --

Re[10]: [Haskell-cafe] Re: monad subexpressions

2007-08-04 Thread Bulat Ziganshin
Hello Brandon, Saturday, August 4, 2007, 7:27:16 PM, you wrote: On Aug 4, 2007, at 11:19 , Bulat Ziganshin wrote: and use it. want to assign a=b/(c+d)? nothing can be easier! just define one more macro! And? Everything above machine code is just macros at various levels of abstraction,

Re: Re[6]: [Haskell-cafe] Re: monad subexpressions

2007-08-04 Thread Claus Reinke
I think that defining lifted versions of every function is dangerous, especially in a widely-used library. Monadic code will start to look pure, and before long someone will be using let expressions and where blocks to share monadic computations rather than using do blocks to share the *results*

Re: Re[10]: [Haskell-cafe] Re: monad subexpressions

2007-08-04 Thread Brandon S. Allbery KF8NH
On Aug 4, 2007, at 11:48 , Bulat Ziganshin wrote: Hello Brandon, Saturday, August 4, 2007, 7:27:16 PM, you wrote: On Aug 4, 2007, at 11:19 , Bulat Ziganshin wrote: and use it. want to assign a=b/(c+d)? nothing can be easier! just define one more macro! And? Everything above machine

Re[12]: [Haskell-cafe] Re: monad subexpressions

2007-08-04 Thread Bulat Ziganshin
Hello Brandon, Saturday, August 4, 2007, 8:44:46 PM, you wrote: That would be why I'm using a language which lets me compose things in complex ways. And just once, abstracting it away into a library, which you seem to be missing. and you hate 'do' syntax sugar? -- Best regards, Bulat

Re: Re[12]: [Haskell-cafe] Re: monad subexpressions

2007-08-04 Thread Brandon S. Allbery KF8NH
On Aug 4, 2007, at 14:51 , Bulat Ziganshin wrote: Hello Brandon, Saturday, August 4, 2007, 8:44:46 PM, you wrote: That would be why I'm using a language which lets me compose things in complex ways. And just once, abstracting it away into a library, which you seem to be missing. and you

RE: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Simon Peyton-Jones
| I've heard Simon (Peyton-Jones) twice now mention the desire to be able | to embed a monadic subexpression into a monad. That would be | http://article.gmane.org/gmane.comp.lang.haskell.prime/2267 and in the | recent OSCON video. | | I still think that this syntax extension has profound

RE: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Simon Peyton-Jones
- | From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chris | Smith | Sent: 03 August 2007 04:30 | To: haskell-cafe@haskell.org | Subject: [Haskell-cafe] Re: monad subexpressions | | Neil Mitchell [EMAIL PROTECTED] wrote: | I think this is a fantastic idea, please do so! | | | Okay

[Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread apfelmus
Chris Smith wrote: I've heard Simon (Peyton-Jones) twice now mention the desire to be able to embed a monadic subexpression into a monad. That would be http://article.gmane.org/gmane.comp.lang.haskell.prime/2267 and in the recent OSCON video. I still think that this syntax extension has

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Neil Mitchell
Hi Perhaps we need to cool this thread down a little bit, and refocus. I personally choose never to use ++ as anything but a statement, since my brain works that way. Other people find different things natural, so can pick what they choose. The one thing you can guarantee is that discussing it

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Claus Reinke
can you please rewrite *p++=*q++ in haskell? assuming these operations i :: V a - IO (V a) -- incr var addr, return old addr r :: V a - IO a -- read var w :: V a - a - IO () -- write var value and this unfolded translation do { qv - r q; w p qv; i p; i q } assuming

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Neil Mitchell
Hi Thinking on the semantic issue for the moment: Can you use (-) outside of a do block? b f (- a) What are the semantics of do b f (- a) where does the evaluation of a get lifted to? Given: if (- a) then f (- b) else g (- c) Do b and c both get monadic bindings regardless of a? if (-

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Mirko Rahn
rewrite *p++=*q++ in haskell? it's one of C idioms. probably, you don't have enough C experience to understand it :) Maybe, but how can *you* understand it, when the standard is vague about it? It could be A: *p=*q; p+=1; q+=1; B: *p=*q; q+=1; p+=1; C: tp=p; tq=q; p+=1; q+=1; *tp=*tq;

Re[2]: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Miguel Mitrofanov
rewrite *p++=*q++ in haskell? MR I always reject such codes when produced by my students. It is just MR unreadable. I even do not understand what you are trying to achieve. MR However, gcc seems it to compile to something like MR *p = *(p+1) ; *q = *(q+1) MR But for what is the '=' good for?

Re[2]: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Bulat Ziganshin
Hello Mirko, Friday, August 3, 2007, 3:32:57 PM, you wrote: rewrite *p++=*q++ in haskell? I always reject such codes when produced by my students. It is just unreadable. it's one of C idioms. probably, you don't have enough C experience to understand it :) So rewriting it in Haskell (of

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Mirko Rahn
rewrite *p++=*q++ in haskell? *p = *(p+1) ; *q = *(q+1) If that's true then GCC has gone insane, because they are completely different. Of course you are right, I just observed at the wrong place..., sorry for that. Though, as any C programmer knows, you really should be using

[Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Chris Smith
apfelmus [EMAIL PROTECTED] wrote: I still think that this syntax extension has profound impact and is a bad idea. Simon's and Neill's use case was the dreaded name-supply monad where the order of effects really doesn't matter up to alpha-conversion. The objection to that use case is that

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Bulat Ziganshin
Hello apfelmus, Friday, August 3, 2007, 12:05:22 PM, you wrote: I still think that this syntax extension has profound impact and is a bad idea. can you please rewrite *p++=*q++ in haskell? -- Best regards, Bulatmailto:[EMAIL PROTECTED]

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Mirko Rahn
rewrite *p++=*q++ in haskell? I always reject such codes when produced by my students. It is just unreadable. I even do not understand what you are trying to achieve. However, gcc seems it to compile to something like *p = *(p+1) ; *q = *(q+1) But for what is the '=' good for? So

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Lutz Donnerhacke
* Bulat Ziganshin wrote: Hello apfelmus, I still think that this syntax extension has profound impact and is a bad idea. can you please rewrite *p++=*q++ in haskell? p = q ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re[2]: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Miguel Mitrofanov
rewrite *p++=*q++ in haskell? MR I always reject such codes when produced by my students. I don't think it's a good idea to reject working code. MR I even do not understand what you are trying to achieve. Well, that just means that your students are a bit smarter than you. And I'd like to

[Haskell-cafe] RE: monad subexpressions

2007-08-03 Thread Chris Smith
Simon Peyton-Jones [EMAIL PROTECTED] wrote: Furthermore there must be no lambda between the monadic splice and the do. I'm curious about this. One could sugar: do tax - getTax return $ map (\price - price * (1 + tax)) bill into: do return $ map (\price - price * (1 + (-

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Sebastian Sylvan
On 03/08/07, apfelmus [EMAIL PROTECTED] 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

[Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Chris Smith
Claus Reinke [EMAIL PROTECTED] wrote: to illustrate why some of us are concerned about this extension, a few examples might help. Claus, I've been saving your message in order to respond to it when I have the time to look over it in detail. I don't think there will be forthcoming answers

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Neil Mitchell
Hi do { do { a; b}; c } is still the same as do { a; do { b; c } } yes? no? perhaps? sometimes? how long did it take you? I'm not entirely sure I understand the point here. The monad laws are defined in terms of = and return. They have never had anything to do with do,

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Claus Reinke
mytransaction = do { x0 - readTVar xvar0 x1 - readTVar xvar1 : xn - readTVar xvarn return $ foo x0 x1 .. xn } Versus mytransaction = return $ foo $(readTVar xvar0) $(readTVar xvar1) .. $(readTVar xvarn) ah, a concrete example. but isn't that the typical use case for ap? mytransaction =

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread David Roundy
On Fri, Aug 03, 2007 at 02:41:05PM +0200, Mirko Rahn wrote: rewrite *p++=*q++ in haskell? it's one of C idioms. probably, you don't have enough C experience to understand it :) Maybe, but how can *you* understand it, when the standard is vague about it? It could be A: *p=*q; p+=1;

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread david48
On 8/3/07, Neil Mitchell [EMAIL PROTECTED] wrote: This is how I understand it: Can you use (-) outside of a do block? b f (- a) b do { ta -a; f ta } or b a = \ta - f ta What are the semantics of do b f (- a) do b a = \ta - f ta Given: if (- a) then f (- b) else g (- c) a = \ta -

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Bulat Ziganshin
Hello Chris, Friday, August 3, 2007, 8:09:49 PM, you wrote: foo = do b' - readTVar b c' - readTVar c d' - readTvar d return (b' + c' / d') It's true that order of effects *can* be important in monads like IO and STM. It's also true, though, that probably 50% of

[Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread apfelmus
Chris Smith wrote: I'm primarily interested in the two cases where one simply has no choice about the use of monads: and those are IO and STM. No, this is not purely functional programming then; but it has some very compelling advantages to Haskell's implementation of these, that I'm afraid

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Claus Reinke
I'll dig for it later if you like. The essence of the matter was a bunch of functions that looked something like this: foo = do b' - readTVar b c' - readTVar c d' - readTvar d return (b' + c' / d') In other words, a string of readTVar statements, followed by one

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Dan Doel
On Friday 03 August 2007, Sebastian Sylvan wrote: On 03/08/07, Claus Reinke [EMAIL PROTECTED] wrote: ah, a concrete example. but isn't that the typical use case for ap? mytransaction = foo `liftM` r xvar0 `ap` r xvar1 .. where r = readTVar I really find it difficult to articulate

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Brandon Michael Moore
much snipping Also, note, if you use the operators in Control.Applicative, then: return $ foo $(bar1) $(bar2) $(bar3) ... can be: return foo * bar1 * bar2 * bar3 ... or: foo $ bar1 * bar2 * bar3 I don't (personally) see how that's any more cryptic than placing brackets

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Stefan O'Rear
On Fri, Aug 03, 2007 at 05:48:18PM -0700, Brandon Michael Moore wrote: General purpose brackets are overkill here. I would really like a simple monadic case. What's so bad about caseM mexpr of p1 - branch1 p2 - branch2 (mexpr = \e - case e of p1 - branch1 p2 - branch2)

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Bulat Ziganshin
Hello apfelmus, Saturday, August 4, 2007, 12:22:53 AM, you wrote: avoid the small layer of imperative code, of course. But the more you treat imperative code as somewhat pure, the greater the danger that the purely functional logic will be buried inside a mess of imperative code. In other

Re[4]: [Haskell-cafe] Re: monad subexpressions

2007-08-03 Thread Bulat Ziganshin
Hello Claus, Friday, August 3, 2007, 7:29:32 PM, you wrote: how about *Object.File.Line.CurPtr++ = *AnotherObject.File.Line.CurPtr++ ? ;) what's the difference?-) let p = Object.File.Line.CurPtr let q = AnotherObject.File.Line.CurPtr do { w p = r q; i p; i q } back to the

Re: [Haskell-cafe] Re: monad subexpressions

2007-08-02 Thread Derek Elkins
On Thu, 2007-08-02 at 21:29 -0600, Chris Smith wrote: Neil Mitchell [EMAIL PROTECTED] wrote: I think this is a fantastic idea, please do so! Okay, I'll do it then. If I have a good weekend, perhaps I'll volunteer a talk at AngloHaskell after all! :) So what about syntax? I agree

[Haskell-cafe] Re: monad subexpressions

2007-08-02 Thread Chris Smith
Neil Mitchell [EMAIL PROTECTED] wrote: I think this is a fantastic idea, please do so! Okay, I'll do it then. If I have a good weekend, perhaps I'll volunteer a talk at AngloHaskell after all! :) So what about syntax? I agree with your objections, so we've got ( - expr ) -- makes