[Haskell-cafe] [announcement] filtrable: class of filtrable containers

Christopher Allen cma at bitemyapp.com
Wed Feb 17 16:30:28 UTC 2016


>Laws

Not for nothing, but there's prior art here for a "filterable" with laws.
https://hackage.haskell.org/package/witherable

On Wed, Feb 17, 2016 at 2:32 AM, Joachim Breitner <mail at joachim-breitner.de>
wrote:

> Hi M,
>
> Am Dienstag, den 16.02.2016, 23:02 -0800 schrieb M Farkas-Dyck:
> > I quietly posted this library to Hackage nearly a year ago, but lately
> > learned that some seeking such a package had difficulty finding it, so
> > i announce it now ☺
> >
> > https://hackage.haskell.org/package/filtrable
> >
> > class Functor f => Filtrable f where
> >     mapMaybe :: (a -> Maybe b) -> f a -> f b
> >     catMaybes :: f (Maybe a) -> f a
> >     filter :: (a -> Bool) -> f a -> f a
> >
> > For laws, see docs on Hackage.
>
> You might want to add laws in the style of
>
>     If this is also a Foldable, then
>        toList . mapMaybe f = mapMapybe f . toList
>        toList . catMaybes = catMaybes . toList
>        toList . filter f = filter f . toList
>
> which would fix the behavior quite tightly.
>
> I wonder if these laws (together with a “well behaved” Foldable) still
> allow any unexpected behavior.
>
> And also whether they follow from your laws (but I don’t think so;
> mapMaybe could do something mean such as duplicating elements if there
> is at least one Nothing in the result).
>
> Do you plan to add instances for all the other data structures in base
> that are filtrable?
>
> Greetings,
> Joachim
>
> --
> Joachim “nomeata” Breitner
>   mail at joachim-breitner.dehttps://www.joachim-breitner.de/
>   XMPP: nomeata at joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F
>   Debian Developer: nomeata at debian.org
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
>


-- 
Chris Allen
Currently working on http://haskellbook.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160217/a5a0994b/attachment.html>


More information about the Haskell-Cafe mailing list