Skip to content

Instantly share code, notes, and snippets.

@lemastero
Created November 25, 2018 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lemastero/01e5d0c1174b05f33c6181dad49e58a7 to your computer and use it in GitHub Desktop.
Save lemastero/01e5d0c1174b05f33c6181dad49e58a7 to your computer and use it in GitHub Desktop.
Simple Haskell implementation for Profunctor and Strong Profunctor to analyse Strong Profunctor laws
swap (a, b) = (b, a)
class Profunctor p where
dimap :: (aa -> a) -> (b -> bb) -> p a b -> p aa bb
lmap :: (aa -> a) -> p a b -> p aa b
lmap f = dimap f id
rmap :: (b -> bb) -> p a b -> p a bb
rmap = dimap id
instance Profunctor (->) where
dimap aa bb ab = bb . ab . aa
class Profunctor p => Strong p where
first :: p a b -> p (a, c) (b, c)
first = dimap swap swap . second
second :: p a b -> p (c, a) (c, b)
second = dimap swap swap . first
instance Strong (->) where
first ab = \(a,c) -> (ab a, c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment