Foldable.Mapped

Shachaf Ben-Kiki shachaf at gmail.com
Mon Jan 4 01:21:16 UTC 2016


It sounds like Coyoneda -- i.e. Mapped with the "a" existential --
might be what you're looking for:
http://hackage.haskell.org/package/kan-extensions-4.2.3/docs/Data-Functor-Coyoneda.html

     Shachaf

On Sun, Jan 3, 2016 at 5:11 PM, Henning Thielemann
<lemming at henning-thielemann.de> wrote:
>
> On Mon, 4 Jan 2016, Oliver Charles wrote:
>
>> Could you provide some examples where you have found it useful?
>
>
> E.g. Set has Foldable instance, but not Functor. Using Mapped I can
> implement argmax in a generic way, such that it also works on Set.
>
> argmax :: (Ord b, Foldable f) => (a -> b) -> f a -> a
> argmax f = snd . Fold.maximumBy (comparing fst) . Mapped (\a -> (f a, a))
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


More information about the Libraries mailing list