Many functions can be generalised

David Menendez dave at zednenem.com
Sun Dec 4 05:22:56 UTC 2016


On Sat, Dec 3, 2016 at 2:32 PM, David Feuer <david.feuer at gmail.com> wrote:

> You can also sift monomorphic containers using my class, which should
> probably be called MonoSiftable.
>
> data IntList = Cons !Int IntList | Nil
>
> instance Siftable Int IntList where
>   sift _ Nil = Nil
>   sift p (Cons x xs)
>     | p x = Cons x (sift p xs)
>     | otherwise = sift p xs
>

You can also use it with contra-variant or invariant type constructors,
e.g.,

instance Siftable a (a -> Bool) where
    sift f g = \x -> f x && g x

-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20161204/9802a45c/attachment.html>


More information about the Libraries mailing list