<p dir="ltr">That's what I was thinking too. While that's not Haskell 98, I believe it can be justified on Haskell 98 grounds by approximate equivalence with the representation of a foldable container by a binary tree. I'm no expert, but I think the hypothetical alternative formulation might look like this:</p>
<p dir="ltr">--Free magma<br>
data Tree a = Leaf a | Bin (Tree a) (Tree a) deriving (Functor, Foldable)</p>
<p dir="ltr">--Adjoin an identity and a phantom.<br>
--The phantom isn't Haskell 98, but<br>
--it would be possible to accomplish the<br>
--same purpose in Haskell 98<br>
data R (f :: * -> *) a = Empty | FM (Tree a) deriving (Functor, Foldable)</p>
<p dir="ltr">--Improper, but probably sane for the purpose<br>
instance Monoid (R f a) where<br>
  mempty = Empty<br>
  mappend Empty ys = ys<br>
  mappend xs Empty = xs<br>
  mappend (FM xs) (FM ys) = FM (Bin xs ys)</p>
<p dir="ltr">rep :: Foldable f => f a -> R f a<br>
rep = foldMap (FM . Leaf)</p>
<p dir="ltr">We can apply rep to a foldable container to get a reusable representation of that container for folding purposes that is also a Functor.</p>
<div class="gmail_quote">On Jan 3, 2016 8:21 PM, "Shachaf Ben-Kiki" <<a href="mailto:shachaf@gmail.com">shachaf@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It sounds like Coyoneda -- i.e. Mapped with the "a" existential --<br>
might be what you're looking for:<br>
<a href="http://hackage.haskell.org/package/kan-extensions-4.2.3/docs/Data-Functor-Coyoneda.html" rel="noreferrer" target="_blank">http://hackage.haskell.org/package/kan-extensions-4.2.3/docs/Data-Functor-Coyoneda.html</a><br>
<br>
     Shachaf<br>
<br>
On Sun, Jan 3, 2016 at 5:11 PM, Henning Thielemann<br>
<<a href="mailto:lemming@henning-thielemann.de">lemming@henning-thielemann.de</a>> wrote:<br>
><br>
> On Mon, 4 Jan 2016, Oliver Charles wrote:<br>
><br>
>> Could you provide some examples where you have found it useful?<br>
><br>
><br>
> E.g. Set has Foldable instance, but not Functor. Using Mapped I can<br>
> implement argmax in a generic way, such that it also works on Set.<br>
><br>
> argmax :: (Ord b, Foldable f) => (a -> b) -> f a -> a<br>
> argmax f = snd . Fold.maximumBy (comparing fst) . Mapped (\a -> (f a, a))<br>
><br>
> _______________________________________________<br>
> Libraries mailing list<br>
> <a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>