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

Oleg Grenrus oleg.grenrus at iki.fi
Wed Feb 17 08:57:27 UTC 2016


Hi, Sean,

I guess that’s why there is a disclaimer:

   “If this is **also** a Foldable, then”

Another similar example is `Hashable` which doesn’t require things to be `Eq`, yet states the infectivity law.

- Oleg

> On 17 Feb 2016, at 10:50, Sean Leather <sean.leather at gmail.com> wrote:
> 
> Hi Joachim,
> 
> On Wed, Feb 17, 2016 at 10:32 AM, Joachim Breitner wrote:
> 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 <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.
> 
> Why would you specify laws for Filtrable w.r.t. Foldable, when Foldable is not part of the definition?
> 
> There is at least one potential application for Filtrable for a type that isn't a Foldable:
> 
>   https://github.com/reflex-frp/reflex/pull/44 <https://github.com/reflex-frp/reflex/pull/44>
> 
> Regards,
> Sean
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160217/a3cd7d4b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160217/a3cd7d4b/attachment.sig>


More information about the Haskell-Cafe mailing list