<div dir="ltr"><div>>Laws<br><br></div>Not for nothing, but there's prior art here for a "filterable" with laws. <a href="https://hackage.haskell.org/package/witherable">https://hackage.haskell.org/package/witherable</a><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 17, 2016 at 2:32 AM, Joachim Breitner <span dir="ltr"><<a href="mailto:mail@joachim-breitner.de" target="_blank">mail@joachim-breitner.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi M,<br>
<span class=""><br>
Am Dienstag, den 16.02.2016, 23:02 -0800 schrieb M Farkas-Dyck:<br>
> I quietly posted this library to Hackage nearly a year ago, but lately<br>
> learned that some seeking such a package had difficulty finding it, so<br>
> i announce it now ☺<br>
><br>
> <a href="https://hackage.haskell.org/package/filtrable" rel="noreferrer" target="_blank">https://hackage.haskell.org/package/filtrable</a><br>
><br>
> class Functor f => Filtrable f where<br>
> mapMaybe :: (a -> Maybe b) -> f a -> f b<br>
> catMaybes :: f (Maybe a) -> f a<br>
> filter :: (a -> Bool) -> f a -> f a<br>
><br>
> For laws, see docs on Hackage.<br>
<br>
</span>You might want to add laws in the style of <br>
<br>
If this is also a Foldable, then <br>
toList . mapMaybe f = mapMapybe f . toList<br>
toList . catMaybes = catMaybes . toList<br>
toList . filter f = filter f . toList<br>
<br>
which would fix the behavior quite tightly.<br>
<br>
I wonder if these laws (together with a “well behaved” Foldable) still<br>
allow any unexpected behavior.<br>
<br>
And also whether they follow from your laws (but I don’t think so;<br>
mapMaybe could do something mean such as duplicating elements if there<br>
is at least one Nothing in the result).<br>
<br>
Do you plan to add instances for all the other data structures in base<br>
that are filtrable?<br>
<br>
Greetings,<br>
Joachim<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Joachim “nomeata” Breitner<br>
<a href="mailto:mail@joachim-breitner.de">mail@joachim-breitner.de</a> • <a href="https://www.joachim-breitner.de/" rel="noreferrer" target="_blank">https://www.joachim-breitner.de/</a><br>
XMPP: <a href="mailto:nomeata@joachim-breitner.de">nomeata@joachim-breitner.de</a> • OpenPGP-Key: 0xF0FBF51F<br>
Debian Developer: <a href="mailto:nomeata@debian.org">nomeata@debian.org</a><br>
<br>
</font></span><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr">Chris Allen<br><div><span style="font-size:12.8000001907349px">Currently working on </span><a href="http://haskellbook.com" target="_blank">http://haskellbook.com</a></div></div></div></div></div></div>
</div>