RE: [Haskell-cafe] Re: IO exception not being caught

Indeed! I always use braces and semicolons with do-notation. You are free to do so too! Nothing requires you to use layout. Indeed, you can freely mix the two. Simon | -----Original Message----- | From: haskell-cafe-bounces@haskell.org [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Joel | Reymont | Sent: 16 November 2005 15:37 | To: Haskell Cafe | Subject: [Haskell-cafe] Re: IO exception not being caught | | After almost two months with Haskell I'm starting to understand why | its use is not as widespread as... well pick a favorite language of | your own. My issue was that of indentation. | | Compare this working version: | | liftIOTrap io = | do mx <- liftIO (do x <- io | return (return x) | `catchError` | (\e -> do let x = fromIOError e | trace_ $ "Caught " ++ x | return $ throwError x | )) | mx | | With the one below | | On Nov 16, 2005, at 2:27 PM, Joel Reymont wrote: | | >> liftIOTrap io = | >> do mx <- liftIO (do x <- io | >> return (return x) | >> `catchError` | >> (\e -> return (throwError | >> (fromIOError e)))) | >> mx | | -- | http://wagerlabs.com/ | | | | | | _______________________________________________ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe

Simon Peyton-Jones wrote:
Indeed! I always use braces and semicolons with do-notation. You are free to do so too! Nothing requires you to use layout. Indeed, you can freely mix the two.
I would not recommend braces and semicolons, because these allow a bad layout (easy to parse for a compiler, but hard to read for a human), unless you invest the time to make a tidy layout despite the braces and semicolons. (So why not only make a tidy layout?) Surely, a different layout may change your semantics (in rare cases). A missplaced "_ -> error ..." case usually causes a pattern warning.
| >> liftIOTrap io = | >> do mx <- liftIO (do x <- io | >> return (return x) | >> `catchError` | >> (\e -> return (throwError | >> (fromIOError e))))
I'ld rather avoid the infix `catchError' and write: liftIO $ catchError (do ... ) $ \e -> Cheers Christian

Indeed! I always use braces and semicolons with do-notation. You are free to do so too! Nothing requires you to use layout. Indeed, you can freely mix the two.
I would not recommend braces and semicolons, because these allow a bad layout (easy to parse for a compiler, but hard to read for a human), unless you invest the time to make a tidy layout despite the braces and semicolons. (So why not only make a tidy layout?)
Unless you use a simplistic text editor, the braces and semi-colons allow the text editor to do the layout for you. While I find the layout notation attractively clean, I find the redundancy of autolayout+braces+semicolons to save me from a lot of trouble. Stefan

On 16/11/05, Stefan Monnier
Indeed! I always use braces and semicolons with do-notation. You are free to do so too! Nothing requires you to use layout. Indeed, you can freely mix the two.
I would not recommend braces and semicolons, because these allow a bad layout (easy to parse for a compiler, but hard to read for a human), unless you invest the time to make a tidy layout despite the braces and semicolons. (So why not only make a tidy layout?)
Unless you use a simplistic text editor, the braces and semi-colons allow the text editor to do the layout for you. While I find the layout notation attractively clean, I find the redundancy of autolayout+braces+semicolons to save me from a lot of trouble.
If your editor is a little smarter still, it can do the Haskell layout without braces automatically too. The emacs mode helps with this. Yi/hIDE should be able to do it perfectly once it's in a generally usable state. :) - Cale

On Thursday 17 November 2005 03:44, Cale Gibbard wrote:
On 16/11/05, Stefan Monnier
wrote: Indeed! I always use braces and semicolons with do-notation. You are free to do so too! Nothing requires you to use layout. Indeed, you can freely mix the two.
I would not recommend braces and semicolons, because these allow a bad layout (easy to parse for a compiler, but hard to read for a human), unless you invest the time to make a tidy layout despite the braces and semicolons. (So why not only make a tidy layout?)
Unless you use a simplistic text editor, the braces and semi-colons allow the text editor to do the layout for you. While I find the layout notation attractively clean, I find the redundancy of autolayout+braces+semicolons to save me from a lot of trouble.
If your editor is a little smarter still, it can do the Haskell layout without braces automatically too. The emacs mode helps with this. Yi/hIDE should be able to do it perfectly once it's in a generally usable state. :)
Hmm, how would your super intelligent text editor layout the ambigous example of the OP? Well, never mind: either way might be the wrong one, depending on what the program is /supposed/ to do. Ben

Benjamin Franksen wrote:
If your editor is a little smarter still, it can do the Haskell layout without braces automatically too. The emacs mode helps with this. Yi/hIDE should be able to do it perfectly once it's in a generally usable state. :)
Hmm, how would your super intelligent text editor layout the ambigous example of the OP? Well, never mind: either way might be the wrong one, depending on what the program is /supposed/ to do.
It would alternate between them as you push TAB, of course. -k

On Thursday 17 November 2005 11:42, Ketil Malde wrote:
Benjamin Franksen wrote:
If your editor is a little smarter still, it can do the Haskell layout without braces automatically too. The emacs mode helps with this. Yi/hIDE should be able to do it perfectly once it's in a generally usable state. :)
Hmm, how would your super intelligent text editor layout the ambigous example of the OP? Well, never mind: either way might be the wrong one, depending on what the program is /supposed/ to do.
It would alternate between them as you push TAB, of course.
Nice solution. Not fool-proof either: you need to know beforehand when to try and ush TAB a second time; but probably ok. Ideal would be a pop-up menu presenting all possible choices; the difficult part being how to represent the choices so that one can easily find out which corresponds to what one wants, and still manage to keep them to less than a screenful of code ;-) Ben

On Wed, 16 Nov 2005, Cale Gibbard wrote:
If your editor is a little smarter still, it can do the Haskell layout without braces automatically too. The emacs mode helps with this. Yi/hIDE should be able to do it perfectly once it's in a generally usable state. :)
The one I'm looking forward to is an editor that'll de-layout code and show me the resulting braces and semicolons (albeit highlighted differently to ones I put there myself). -- flippa@flippac.org Society does not owe people jobs. Society owes it to itself to find people jobs.
participants (7)
-
Benjamin Franksen
-
Cale Gibbard
-
Christian Maeder
-
Ketil Malde
-
Philippa Cowderoy
-
Simon Peyton-Jones
-
Stefan Monnier