Re: [Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-31 Thread Yitzchak Gale
Edward Kmett wrote: > I felt I should probably mention that ultimately what was done is I moved > NonEmpty all the way down into semigroups and chose >> sconcat :: NonEmpty a -> a > at it was the closest analogue to the current mconcat behavior. > So, request accomodated. ;) Indeed, this is an exc

Re: [Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-30 Thread Edward Kmett
I felt I should probably mention that ultimately what was done is I moved NonEmpty all the way down into semigroups and chose > sconcat :: NonEmpty a -> a at it was the closest analogue to the current mconcat behavior. So, request accomodated. ;) -Edward On Tue, May 3, 2011 at 7:23 PM, Edward

Re: [Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-14 Thread Henning Thielemann
Yitzchak Gale schrieb: > When using it in practice, it would be very useful > to have an analogue to the mconcat method of > Monoid. It has the obvious default implementation, > but allows for an optimized implementation for > specific instances. That turns out to be something > that comes up all

Re: [Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-04 Thread John Lato
On Wed, May 4, 2011 at 1:25 PM, Edward Kmett wrote: > On Wed, May 4, 2011 at 7:40 AM, John Lato wrote: > >> From: Edward Kmett >>> >>> >>> On Tue, May 3, 2011 at 3:43 PM, Yitzchak Gale wrote: >>> >>> > I'm sure there are countless other natural examples of semigroups >>> > in the wild, and tha

Re: [Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-04 Thread Edward Kmett
On Wed, May 4, 2011 at 7:40 AM, John Lato wrote: > From: Edward Kmett >> >> >> On Tue, May 3, 2011 at 3:43 PM, Yitzchak Gale wrote: >> >> > I'm sure there are countless other natural examples of semigroups >> > in the wild, and that the typical non-trivial ones will benefit >> > from an optimiz

Re: [Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-04 Thread John Lato
> > From: Edward Kmett > > On Tue, May 3, 2011 at 3:43 PM, Yitzchak Gale wrote: > > > I'm sure there are countless other natural examples of semigroups > > in the wild, and that the typical non-trivial ones will benefit > > from an optimized sconcat. > > > > Sold! (modulo the semantic considerati

Re: [Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-03 Thread Edward Kmett
Another option (upon reflection) would be to just transplant the NonEmpty type from http://hackage.haskell.org/packages/archive/streams/0.6.1.1/doc/html/Data-Stream-NonEmpty.html data NonEmpty a = a :| [a]

Re: [Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-03 Thread Edward Kmett
On Tue, May 3, 2011 at 3:43 PM, Yitzchak Gale wrote: > Edward Kmett wrote: > > sconcat :: [a] -> a -> a > > with either the semantics you supplied or something like > > sconcat = appEndo . mconcat . map diff > > > The sconcat we have been discussing is > > sconcat = flip $ appEndo . getDual . m

Re: [Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-03 Thread Yitzchak Gale
Edward Kmett wrote: > sconcat :: [a] -> a -> a > with either the semantics you supplied or something like > sconcat = appEndo . mconcat . map diff The sconcat we have been discussing is sconcat = flip $ appEndo . getDual . mconcat . map (Dual . Endo . flip (<>)) (avoiding the use of Dual.diff.Du

Re: [Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-03 Thread Edward Kmett
On Tue, May 3, 2011 at 7:12 AM, Yitzchak Gale wrote: > Hi Edward, > > Thanks much for the very useful semigroups > package. > > When using it in practice, it would be very useful > to have an analogue to the mconcat method of > Monoid. It has the obvious default implementation, > but allows for a

Re: [Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-03 Thread Stephen Tetley
On 3 May 2011 13:26, Yitzchak Gale wrote: >> Both are "kind of, sort of" bringing you up to a Monoid though... > > altconcat and sconcatMaybe are doing that, because you > need to decide what to do with an empty list when you > define the instance. Holger's interface is not doing that, > because

Re: [Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-03 Thread Yitzchak Gale
Stephen Tetley wrote: > There is that formulation, though usually I find I need to do it with > an alternative instead: > altconcat alt []     = alt > altconcat _   (a:as) = go a as >  where >    go acc [] = acc >    go acc (b:bs) = go (acc <> b) bs But the whole reason we need this as a method is

Re: [Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-03 Thread Yitzchak Gale
Stephen Tetley wrote: >> Does it have an obvious default implementation, bearing in mind it we >> might really want a total function? >> >> sconcat []     = error "Yikes - I wish this was total!" >> sconcat [a]    = a >> sconcat (a:as) = a <> sconcat as Holger Siegel wrote: > You have to provide t

Re: [Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-03 Thread Stephen Tetley
There is that formulation, though usually I find I need to do it with an alternative instead: altconcat alt [] = alt altconcat _ (a:as) = go a as where go acc [] = acc go acc (b:bs) = go (acc <> b) bs Both are "kind of, sort of" bringing you up to a Monoid though... On 3 May 201

Re: [Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-03 Thread Holger Siegel
Am 03.05.2011 um 13:39 schrieb Stephen Tetley: > Does it have an obvious default implementation, bearing in mind it we > might really want a total function? > > sconcat [] = error "Yikes - I wish this was total!" > sconcat [a]= a > sconcat (a:as) = a <> sconcat as You have to provide th

Re: [Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-03 Thread Stephen Tetley
Does it have an obvious default implementation, bearing in mind it we might really want a total function? sconcat [] = error "Yikes - I wish this was total!" sconcat [a]= a sconcat (a:as) = a <> sconcat as Best wishes Stephen On 3 May 2011 12:12, Yitzchak Gale wrote: [SNIP] > It has th

[Haskell-cafe] Please add a method for optimized concat to the Semigroup class

2011-05-03 Thread Yitzchak Gale
Hi Edward, Thanks much for the very useful semigroups package. When using it in practice, it would be very useful to have an analogue to the mconcat method of Monoid. It has the obvious default implementation, but allows for an optimized implementation for specific instances. That turns out to be