Alternative.some and NonEmpty

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Sun Mar 5 11:49:44 UTC 2017


On 5 March 2017 at 21:51, Vladislav Zavialov <vlad.z.4096 at gmail.com> wrote:
> Since 'Data.List.NonEmpty' is now in 'base', it makes sense to change
> the type of 'some' from
>
> some :: Alternative f => f a -> f [a]
>
> to
>
> some :: Alternative f => f a -> f (NonEmpty a)
>
> as it's guaranteed to return a non-empty list.
>
> Currently, both users and implementors of 'Alternative' instances are
> at a disadvantage. The users have to use the unsafe NonEmpty.fromList
> function to take advantage of the fact that the result of 'some' is
> indeed non-empty. The implementors have more space for error - it's
> possible to accidentally return an empty list.

The disadvantage is also for people trying to maintain a code base,
though that's solvable with CPP if needed.

However, this also affects the default instances.

(As a user and implementor of Alternative instances, I've never found
myself at a disadvantage for using the current type.)

> I volunteer to implement. Does everyone agree it's a good idea?

I'm -0.5.

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
http://IvanMiljenovic.wordpress.com


More information about the Libraries mailing list