Last active
July 27, 2025 19:42
-
-
Save echatav/59ccd43ff400d75ecd0fce821524e618 to your computer and use it in GitHub Desktop.
profunctorial container constraint characterizations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Profunctorial where | |
| import Control.Applicative | |
| import Data.Function | |
| import Data.Functor | |
| import Data.Functor.Contravariant | |
| import Data.Profunctor | |
| import Witherable | |
| class Foldable f where | |
| foldP :: | |
| ( Strong p, Choice p | |
| , forall x. Applicative (p x) | |
| , forall x. Contravariant (p x) | |
| ) => p a b -> p (f a) (f b) | |
| class (Functor f, Foldable f) => Traversable f where | |
| -- prop> fmap = traverseP | |
| -- prop> foldP = traverseP | |
| traverseP :: | |
| ( Strong p, Choice p | |
| , forall x. Applicative (p x) | |
| ) => p a b -> p (f a) (f b) | |
| class Applicative f => Cotraversable f where | |
| cotraverseP :: | |
| ( Closed p | |
| , forall x. Applicative (p x) | |
| ) => p a b -> p (f a) (f b) | |
| replicateP :: | |
| ( Traversable f | |
| , Cotraversable f | |
| , Profunctor p | |
| , forall x. Applicative (p x) | |
| ) => p a b -> p (f a) (f b) | |
| replicateP p = | |
| traverse (\f -> lmap f p) (cotraverse id id) | |
| where | |
| cotraverse = runCostar . cotraverseP . Costar | |
| traverse = runStar . traverseP . Star | |
| witherP :: | |
| ( Traversable f | |
| , Filterable f | |
| , Strong p, Choice p | |
| , forall x. Alternative (p x) | |
| ) => p a b -> p (f a) (f b) | |
| witherP = rmap catMaybes . traverseP . optional |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment