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

Joachim Breitner mail at joachim-breitner.de
Wed Feb 17 08:32:56 UTC 2016


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160217/61fcb627/attachment.sig>


More information about the Haskell-Cafe mailing list