Re: [Haskell-cafe] A convenient way to deal with conditional function composition?

2007-04-11 Thread Maxime Henrion
Chris Kuklewicz wrote: > Nicolas Frisby wrote: > >> Not portably. > >> > >> [EMAIL PROTECTED]:~$ ghc-6.4.2 -e '( ("foo"++) `Data.Monoid.mappend` > >> ("bar"++) ) "END"' > >> "foobarEND" > >> [EMAIL PROTECTED]:~$ ghc-6.6 -e '( ("foo"++) `Data.Monoid.mappend` > >> ("bar"++) ) "END"' > >> "fooENDbar

Re: [Haskell-cafe] A convenient way to deal with conditional function composition?

2007-04-10 Thread Chris Kuklewicz
Nicolas Frisby wrote: >> Not portably. >> >> [EMAIL PROTECTED]:~$ ghc-6.4.2 -e '( ("foo"++) `Data.Monoid.mappend` >> ("bar"++) ) "END"' >> "foobarEND" >> [EMAIL PROTECTED]:~$ ghc-6.6 -e '( ("foo"++) `Data.Monoid.mappend` >> ("bar"++) ) "END"' >> "fooENDbarEND" >> >> >> -- 6.6 sources >> instance

Re: [Haskell-cafe] A convenient way to deal with conditional function composition?

2007-04-10 Thread Nicolas Frisby
Using the Endo newtype can avoid such ambiguities: http://darcs.haskell.org/packages/base/Data/Monoid.hs newtype Endo a = Endo { appEndo :: a -> a } instance Monoid (Endo a) where mempty = Endo id Endo f `mappend` Endo g = Endo (f . g) Endo allows you to explicitly select the m

Re: [Haskell-cafe] A convenient way to deal with conditional function composition?

2007-04-10 Thread Stefan O'Rear
On Tue, Apr 10, 2007 at 02:33:41PM +0100, Chris Kuklewicz wrote: > Well, since ((.) :: ShowS -> ShowS -> ShowS) is a Monoid, you can use Writer > to > create the result: Not portably. [EMAIL PROTECTED]:~$ ghc-6.4.2 -e '( ("foo"++) `Data.Monoid.mappend` ("bar"++) ) "END"' "foobarEND" [EMAIL PRO

Re: [Haskell-cafe] A convenient way to deal with conditional function composition?

2007-04-10 Thread Chris Kuklewicz
Maxime Henrion wrote: > Hello all, > > > I have found myself writing instances of Show for some types of > mine, and I did so by defining the showsPrec function, for performance > reasons. I ended up with code that I find quite inelegant. Here's > an example: > > data Move = Move { >

[Haskell-cafe] A convenient way to deal with conditional function composition?

2007-04-10 Thread Maxime Henrion
Hello all, I have found myself writing instances of Show for some types of mine, and I did so by defining the showsPrec function, for performance reasons. I ended up with code that I find quite inelegant. Here's an example: data Move = Move { movePiece :: PieceType