[Haskell-cafe] Please add instance Semigroup Text
Yitzchak Gale
gale at sefer.org
Tue May 3 22:14:40 CEST 2011
I wrote:
>>> Could you please add a Semigroup instance for Text?
Edward Kmett wrote:
> Unfortunately, I don't think I can really bring myself to do either.
> I was deliberately trying to keep the number of dependencies for the
> semigroups as low as possible...
You are quite right. These should really be defined in their
respective packages. I don't think it's too onerous for them
to add a dependency on semigroups, even before you
reverse the few lightweight dependencies that semigroups has.
Bryan O'Sullivan wrote:
>> I'd strongly recommend writing an instance for the text
>> package's Builder type instead. Vastly more efficient
>> for non-trivial jobs.
Well, in my case, I'm iterating over many small Texts, slicing
and dicing small groups of them in various ways to look for
overlaps, and splicing the pieces back together in different
combinations. It's quite fast as it is; what I'm looking for is to
make the formulas look simpler and more understandable.
I doubt that builders will be any help for that. Whereas using
<> from semigroups instead of `T.append` or `mappend`
is a huge help.
Apart from my own use case, semigroups are a simple
and fundamental idiom that I think will become much
more widely used as people become more aware of them.
Just like every Monad should have a Functor instance,
every Monoid should have a Semigroup instance.
Thanks,
Yitz
More information about the Haskell-Cafe
mailing list