
Hi M, - I’d also like to see instances for types in containers, unordered-containers, vector and semigroup. - The OtherLicense seems a bit scary (even the contents aren’t), is there a good reason why you don’t use more familiar MIT or BSD3? If you don’t mind I can make a PR for the instances. And one more comment: The law: filter f = mapMaybe (liftA2 (<$) id (guard ∘ f)) is very hard to understand. filter f = mapMaybe (\x -> if f x then Just x else Nothing) is longer, but IMHO much simpler. Or if you really want to code golf, then maybe: filter f = mapMaybe (mfilter f . Just) - Oleg
On 17 Feb 2016, at 10:32, Joachim Breitner
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@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe