Open gibiansky opened 9 years ago
Do you want to use the name singleton
or can you use opoint
?
I'm currently using opoint
, but I'm wondering whether there is a design which would allow singleton
to be used here. (As someone who isn't fluent in mono-traversable
, the names for the typeclass MonoPointed
and function opoint
are not terribly intuitive; why not just use singleton
?)
(Also, I would not have guessed to use opoint
if I had not looked at the source of singleton
. Though maybe that's documented somewhere, Hackage is just not displaying recent documentation...)
The concept here is probably that singleton implies a container of multiple items, so the IsSequence
constraint may have been used to make that sensible. But that is limiting.
It would make sense to me to loosen the constraint to (MonoFoldable, MonoPointed)
, since MonoFoldable
contains toList
. Although that really means loosening it to MonoPointed
and being the same as opoint
since MonoPointed
requires MonoFoldable
for its law.
I'm afraid I don't really understand the naming behind opoint
and MonoPointed
. Why not singleton
and CanSingleton
? Alternatively, why not just singleton
instead of opoint
(MonoPointed
doesn't really matter so much, it's just the typeclass)
CanSingleton is the old naming of ad-hoc typeclasses. MonoPointed follows a law: otoList . mconcat . map opoint == id
The pointed concept has a history in Haskell, but I am not opposed re-naming it to singleton
(and MonoSingleton
.
Would you would be happy with singleton :: MonoPointed seq => Element seq -> seq
, or is that not the case?
I think the name of the typeclass doesn't matter too much, but having it be named "singleton" is important. Do yes, I think that would be fine.
As an side, could you briefly explain (or give a resource) as to the "pointed" naming? MonoSingleton is more intuitive imi, but didn't really matter for the type class name.
Thanks! On Oct 10, 2014 7:01 PM, "Greg Weber" notifications@github.com wrote:
CanSingleton is the old naming of ad-hoc typeclasses. MonoPointed follows a law: otoList . mconcat . map opoint == id The pointed concept has a history in Haskell, but I am not opposed re-naming it to singleton (and MonoSingleton.
Would you would be happy with singleton :: MonoPointed seq => Element seq -> seq, or is that not the case?
— Reply to this email directly or view it on GitHub https://github.com/snoyberg/classy-prelude/issues/87#issuecomment-58734568 .
Haskell tends towards category names rather than intuitive ones :). The current classy-prelude is mostly about using existing abstractions and names. But given that the pointed abstraction has almost no usage in the community we could certainly try to change the name.
https://hackage.haskell.org/package/category-extras-0.53.1/docs/Control-Functor-Pointed.html
Currently, mono-traversable and classy-prelude provide a function singletonSet
for this use case. This arose from trying to address three different use cases: Sequence/Functor instances like Vector or ByteString, Sets, and Maps. However, it seems like we now have a way (via MonoPointed) to combined the first two cases (Map is still inherently different). I'm not opposed to changing singleton
to just being a nicer name for opoint
.
I would like to be able to use
singleton
withSet a
. This is exported byData.Set
, but can't be implemented usingclassy-prelude
becausesingleton
requiresIsSequence
, whichSet
isn't. Is this possible some other way?