2023-03-06 21:37:27 -05:00
|
|
|
module Data.Profunctor.Sieve
|
|
|
|
|
2023-03-08 15:05:07 -05:00
|
|
|
import Control.Applicative.Const
|
2023-03-06 21:37:56 -05:00
|
|
|
import Control.Monad.Identity
|
|
|
|
import Data.Morphisms
|
2023-03-06 21:37:27 -05:00
|
|
|
import Data.Profunctor
|
|
|
|
|
|
|
|
%default total
|
|
|
|
|
|
|
|
|
2023-03-07 22:15:08 -05:00
|
|
|
------------------------------------------------------------------------------
|
|
|
|
-- Interfaces
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
||| A profunctor `p` is a sieve on `f` if it is a subprofunctor of `Star f`.
|
2023-03-06 21:37:27 -05:00
|
|
|
public export
|
|
|
|
interface (Profunctor p, Functor f) => Sieve p f | p where
|
|
|
|
sieve : p a b -> a -> f b
|
|
|
|
|
|
|
|
|
2023-03-07 22:15:08 -05:00
|
|
|
||| A profunctor `p` is a cosieve on `f` if it is a subprofunctor of `Costar f`.
|
|
|
|
public export
|
|
|
|
interface (Profunctor p, Functor f) => Cosieve p f | p where
|
|
|
|
cosieve : p a b -> f a -> b
|
|
|
|
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
-- Implementations
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2023-03-30 13:32:45 -04:00
|
|
|
public export
|
2023-03-06 21:37:56 -05:00
|
|
|
Sieve Morphism Identity where
|
|
|
|
sieve (Mor f) = Id . f
|
|
|
|
|
2023-03-07 22:15:08 -05:00
|
|
|
||| A named implementation of `Sieve` for function types.
|
|
|
|
||| Use this to avoid having to use a type wrapper like `Morphism`.
|
2023-03-30 13:32:45 -04:00
|
|
|
public export
|
2023-03-06 21:37:56 -05:00
|
|
|
[Function] Sieve (\a,b => a -> b) Identity using Profunctor.Function where
|
|
|
|
sieve = (Id .)
|
|
|
|
|
2023-03-30 13:32:45 -04:00
|
|
|
public export
|
2023-03-06 21:37:56 -05:00
|
|
|
Functor f => Sieve (Kleislimorphism f) f where
|
|
|
|
sieve = applyKleisli
|
|
|
|
|
2023-03-30 13:32:45 -04:00
|
|
|
public export
|
2023-03-06 21:37:56 -05:00
|
|
|
Functor f => Sieve (Star f) f where
|
|
|
|
sieve = applyStar
|
|
|
|
|
2023-03-30 13:32:45 -04:00
|
|
|
public export
|
2023-03-08 15:05:07 -05:00
|
|
|
Sieve (Forget r) (Const r) where
|
|
|
|
sieve (MkForget k) = MkConst . k
|
|
|
|
|
2023-03-06 21:37:56 -05:00
|
|
|
|
2023-03-30 13:32:45 -04:00
|
|
|
public export
|
2023-03-06 21:37:56 -05:00
|
|
|
Cosieve Morphism Identity where
|
|
|
|
cosieve (Mor f) = f . runIdentity
|
|
|
|
|
|
|
|
namespace Cosieve
|
2023-03-07 22:15:08 -05:00
|
|
|
||| A named implementation of `Cosieve` for function types.
|
|
|
|
||| Use this to avoid having to use a type wrapper like `Morphism`.
|
2023-03-30 13:32:45 -04:00
|
|
|
public export
|
2023-03-06 21:37:56 -05:00
|
|
|
[Function] Cosieve (\a,b => a -> b) Identity using Profunctor.Function where
|
|
|
|
cosieve = (. runIdentity)
|
|
|
|
|
2023-03-30 13:32:45 -04:00
|
|
|
public export
|
2023-03-06 21:37:56 -05:00
|
|
|
Functor f => Cosieve (Costar f) f where
|
|
|
|
cosieve = applyCostar
|
2023-03-08 15:05:07 -05:00
|
|
|
|
2023-03-30 13:32:45 -04:00
|
|
|
public export
|
2023-03-08 15:05:07 -05:00
|
|
|
Cosieve (Coforget r) (Const r) where
|
|
|
|
cosieve (MkCoforget k) = k . runConst
|