Many functions can be generalised

David Menendez dave at zednenem.com
Sun Dec 4 23:45:24 UTC 2016


On Sun, Dec 4, 2016 at 12:44 AM, David Feuer <david.feuer at gmail.com> wrote:

> On Dec 4, 2016 12:22 AM, "David Menendez" <dave at 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).

-- 
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/82b1b79a/attachment.html>


More information about the Libraries mailing list