[Haskell-cafe] Re: Proper way to write this
Pupeno wrote: On Monday 26 December 2005 02:41, Donn Cave wrote: I don't think it will be too much worse. I would not try to combine the struct updates, in the both case -- it doesn't buy you anything, and pulls you into duplication you don't want. What about this runDaytimeServer :: DaytimeServer - IO DaytimeServer runDaytimeServer dts = do dts' - runStreamDaytimeServer dts dts' - runDgramDaytimeServer dts' return dts' runDaytimeServer dts = runStreamDaytimeServer dts = runDgramDaytimeServer Don't write a - foo return a write foo instead. -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Proper way to write this
Max Vasin wrote: Pupeno wrote: What about this runDaytimeServer :: DaytimeServer - IO DaytimeServer runDaytimeServer dts = do dts' - runStreamDaytimeServer dts dts' - runDgramDaytimeServer dts' return dts' runDaytimeServer dts = runStreamDaytimeServer dts = runDgramDaytimeServer I have seen this pattern many times, and I am surprised it is not present in Control.Monad. (-) :: (a - m b) - (b - m c) - a - m c (-) f g a = f a = g Your code becomes runDaytimeServer = runStreamDaytimeServer - runDgramDaytimeServer This - operator is a very natural composition operator in a Monad, at least to me. It seems to be the most obvious counter-part to '.'. But I could not find anything with that signature in the libraries -- or did I miss it? [And - is typographically sub-optimal, but I can't think of something better]. Jacques ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe