Skip to content

Instantly share code, notes, and snippets.

@gnumonik
Created March 31, 2021 07:34
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 gnumonik/a321defc6ba0af9035653f5ac3693c24 to your computer and use it in GitHub Desktop.
Save gnumonik/a321defc6ba0af9035653f5ac3693c24 to your computer and use it in GitHub Desktop.
Lift a traversal over a kind-indexed type to a traversal over a type that existentially wraps it
someCard :: forall b f. Applicative f
=> (forall f q r t. Applicative f => (b -> f b)
-> Card q r t
-> f (Card q r t))
-> ((b -> f b) -> SomeCard -> f SomeCard)
someCard t = \_ -> h (g t)
where
g :: forall b f. Applicative f
=> (forall q r t . (b -> f b) -> Card q r t -> f (Card q r t))
-> (forall q r t. Card q r t -> f (Card q r t))
g f = f (pure . identity)
h :: forall f. Applicative f
=> (forall q r t. (Card q r t -> f (Card q r t)))
-> (SomeCard -> f SomeCard)
h f = \(MkSomeCard c) -> MkSomeCard <$> f c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment