Pointed [Re: 2014 Applicative => Monad proposal]

Shachaf Ben-Kiki shachaf at gmail.com
Sun May 26 10:22:28 CEST 2013


On Sun, May 26, 2013 at 3:57 AM, Petr Pudlák <petr.mvd at gmail.com> wrote:
>
> I think you hit the nail on the head here. The only places when I missed
> something like Pointed were when I wanted to abstract building some kind of
> collection (Set / [] / Seq / ...). They're all monoids, but you need some
> way how to construct singleton collections. Having MonoidOver would solve
> precisely this problem. I'd certainly prefer something like this over
> Pointed.
>
>

One point in Pointed's favor is that it lets one express "affine
traversals" -- that is, a function with a type like "Pointed f => (a
-> f b) -> T a -> f (T b)". This is like a traversal -- traverse ::
Applicative f => (a -> f b) -> T a -> f (T b) for some Traversable T
-- but guarantees that it traverses either 0 or 1 elements, rather
than 0-or-more. With a Pointed superclass for Applicative an affine
traversal can automatically be used as a regular traversal. I don't
know that this is worth adding a superclass for -- certainly it should
be a separate proposal -- but it's useful for some code, e.g. lens, to
get stronger type guarantees.

    Shachaf



More information about the Libraries mailing list