Closed gittywithexcitement closed 6 years ago
Sounds fine to me, want to send a PR?
On Mon, Jan 15, 2018 at 7:44 PM, Daniel Killebrew notifications@github.com wrote:
Problem:
singleton is not implemented for NonEmpty This does not make sense; obviously you can create a NonEmpty from a single element. Details:
- singleton has the constraint IsSequence seq.
- Monoid is a superclass of IsSequence
- NonEmpty is not an instance Monoid. This makes sense because there's no valid mempty.
- Thus singleton is not implemented for NonEmpty. This does not make sense because you can obviously create a valid NonEmpty container from a single element. The workaround is to use not-well-known functions like opoint or pure to create a NonEmpty. This makes my code less readable, because those functions are not well known (opoint) or not typically used to create a container (pure).
Solution:
Change singleton constraint to MonoPointed. That's all.
The implementation of singleton is: singleton = opoint which only requires a MonoPointed constraint, as opoint is a function of that type class. NonEmpty already is an instance of MonoPointed, so after changing the constraint, singleton will be implemented for NonEmpty.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/snoyberg/mono-traversable/issues/156, or mute the thread https://github.com/notifications/unsubscribe-auth/AADBB7GyGERTGO3y6wUXX1ekvRpxb9aXks5tK455gaJpZM4RewJU .
Will do.
I see that singleton is in Data.Sequence, but MonoPointed is in Data.MonoTraversable. Thus, it would make sense to move singleton, given the updated constraint, but that would break user code. What do you suggest?
What's the motivation for moving it? opoint already exists in Data.MonoTraversable, and singleton is intended to complete the Data.Sequence API for compatibility with libraries like text and bytestring.
On Mon, Jan 15, 2018 at 8:01 PM, Daniel Killebrew notifications@github.com wrote:
Will do.
I see that singleton is in Data.Sequence, but MonoPointed is in Data.MonoTraversable. Thus, it would make sense to move singleton, given the updated constraint, but that would break user code. What do you suggest?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/snoyberg/mono-traversable/issues/156#issuecomment-357752826, or mute the thread https://github.com/notifications/unsubscribe-auth/AADBBw-S3Dw79n9aXzWA30xBYnnxulK4ks5tK5J_gaJpZM4RewJU .
I see. Given that, I see no reason to move it.
Thanks for the super fast feedback!
Problem:
singleton
is not implemented forNonEmpty
This does not make sense; obviously you can create aNonEmpty
from a single element.Details:
singleton
has the constraintIsSequence seq
.Monoid
is a superclass ofIsSequence
NonEmpty
is not an instanceMonoid
. This makes sense because there's no validmempty
.singleton
is not implemented forNonEmpty
. This does not make sense because you can obviously create a validNonEmpty
container from a single element. The workaround is to use not-well-known functions likeopoint
orpure
to create aNonEmpty
. This makes my code less readable, because those functions are not well known (opoint
) or not typically used to create a container (pure
).Solution:
Change
singleton
constraint toMonoPointed
. That's all.The implementation of
singleton
is:singleton = opoint
which only requires aMonoPointed
constraint, asopoint
is a function of that type class.NonEmpty
already is an instance ofMonoPointed
, so after changing the constraint,singleton
will be implemented forNonEmpty
.