[Haskell-cafe] Testing Implementation vs Model - Records or Type Classes?

wren ng thornton wren at freegeek.org
Sat Apr 9 01:55:14 CEST 2011


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



More information about the Haskell-Cafe mailing list