On 4/8/11 8:55 AM, Twan van Laarhoven wrote:
-- this class is useful beyond this FRP library,
-- you might already be able to find it on hackage somewhere
class Functor f => Filterable f where
filter :: (a -> Bool) -> f a -> f a
-- filter p . fmap f == fmap f . filter (p . f)
-- filter (const True) == id
-- filter p . filter q == filter (\x -> p x && q x)

There are a few other methods that should be added to this typeclass. In particular,

    filterMap :: (a -> Maybe b) -> f a -> f b

which fuses the first rule and saves the redundant passes and evaluations.

In a similar vein you may want a class for versions that allow applicative/monadic functions along with the sequenceA/sequence capabilities of Traversable.

--
Live well,
~wren

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to