On Sun, Dec 4, 2016 at 12:44 AM, David Feuer <david.feuer@gmail.com> wrote:
On Dec 4, 2016 12:22 AM, "David Menendez" <dave@zednenem.com> wrote:

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

That looks backwards for your composition law, but I'm a bit tired so I wouldn't swear to it.

You’re right. Of course, they’re all the same if we assume total functions.

Surely you can do the same with the constructor class.

newtype Ab a = Ab (a -> Bool)
instance Siftable Ab where
  siftAway _ = Ab (const False)
  sift p (Ab g) = Ab ...

Ab is contravariant, so you would need something like

siftContraMap :: (a -> Maybe b) -> f b -> f a
 
I'm not sure if my siftAway excludes anything it shouldn't....

I’m not sure it’s possible to define siftAway so that it isn’t equal to sift (const Nothing).

--