[Haskell-cafe] layout problem

Simon Marlow simonmar at microsoft.com
Thu Nov 17 05:24:36 EST 2005


On 16 November 2005 17:15, Christian Maeder wrote:

> 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 ->

I generally prefer to use the "handle" variants rather than "catch":

    liftIO $
       handle my_handler $ do
          x <- io
          return (return x)
    where
      my_handler e = return (throwError (fromIOError e))

Don't be afraid to name things if it makes your code easier to read.

Cheers,
	Simon


More information about the Haskell-Cafe mailing list