[Haskell-cafe] Cleaner way to write code and handle errors?

2011-06-28 Thread John Ky
Hi all, I'm practising my Haskell by writing a simple TCP echo server and finding that getting my program control to be succinct is rather tricky. In particular, I have return () everywhere, my error handling is verbose and I'm not entirely sure my recursion is the cleanest way syntactically to

Re: [Haskell-cafe] Cleaner way to write code and handle errors?

2011-06-28 Thread Ivan Lazar Miljenovic
On 28 June 2011 18:08, John Ky newho...@gmail.com wrote: Hi all, I'm practising my Haskell by writing a simple TCP echo server and finding that getting my program control to be succinct is rather tricky.  In particular, I have return () everywhere, my error handling is verbose and I'm not

Re: [Haskell-cafe] Cleaner way to write code and handle errors?

2011-06-28 Thread Erik de Castro Lopo
Ivan Lazar Miljenovic wrote: I don't think you need all those return () everywhere... And at the end, why do you do line - getLine when you don't use the result? The hlint program would have flagged both of those and possibly others. See: http://community.haskell.org/~ndm/hlint/ Erik --

Re: [Haskell-cafe] Cleaner way to write code and handle errors?

2011-06-28 Thread John Ky
Hi Eric, Ivan, On 28 June 2011 18:32, Erik de Castro Lopo mle...@mega-nerd.com wrote: The hlint program would have flagged both of those and possibly others. See: Cool! It didn't flag either for me, but it recommended replacing ++ (show port)with ++ show port, if then else with unless,

Re: [Haskell-cafe] Cleaner way to write code and handle errors?

2011-06-28 Thread Jonas Almström Duregård
There is the void function in Control.Monad: http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Monad.html#v:void Instead of using return () you can just use void processLine. Also some people like to use the either function instead of matching on Left/Right. In this case

Re: [Haskell-cafe] Cleaner way to write code and handle errors?

2011-06-28 Thread John Ky
Thanks Jonas, I feel much better already: import Control.Concurrent import Control.Exception import Control.Monad import Network import System.IO import System.IO.Error (isEOFError) main = withSocketsDo $ do sListen - listenOn (PortNumber 8000) putStrLn Listening on Port 8000 forkIO $