Skip to content

Instantly share code, notes, and snippets.

@crvdgc
Created October 8, 2021 20:14
Show Gist options
  • Save crvdgc/aa40c55ba16f62fdf4a090850b3510b9 to your computer and use it in GitHub Desktop.
Save crvdgc/aa40c55ba16f62fdf4a090850b3510b9 to your computer and use it in GitHub Desktop.
Deduce the type of `prism`
prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
prism bt seta = dimap seta (either pure (fmap bt)) . right'
type Prism s t a b = forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t)
prism :~: (b -> t) -> (s -> Either t a) -> p a (f b) -> p s (f t)
class Profunctor p => Choice p where
left' :: p a b -> p (Either a c) (Either b c)
right' :: p a b -> p (Either c a) (Either c b)
either :: (a -> c) -> (b -> c) -> Either a b -> c
either :=: (a0 -> c0) -> (b0 -> c0) -> Either a0 b0 -> c0
either :>: (a0 -> f0 c0) -> (f0 b -> f0 c0) -> Either a0 (f0 b) -> f0 c0
either :>: (c0 -> f0 c0) -> (f0 b -> f0 c0) -> Either c0 (f0 b) -> f0 c0
either :>: (t -> f t) -> (f b -> f t) -> Either t (f b) -> f t
dimap :: (a -> b) -> (c -> d) -> p b c -> p a d
dimap :>: (s -> Either t a) -> (c1 -> d1) -> p (Either t a) c1 -> p s d1
dimap :>: (s -> Either t a) -> (c1 -> f t) -> p (Either t a) c1 -> p s (f t)
dimap :>: (s -> Either t a) -> ((Either c (f b) -> f t) -> p (Either t a) (Either c (f b)) -> p s (f t)
right' :: p a b -> p (Either c a) (Either c b)
right' :>: p a (f b) -> p (Either c2 a) (Either c2 (f b))
right' :>: p a (f b) -> p (Either t a) (Either t (f b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment