Skip to content

Instantly share code, notes, and snippets.

@mbrcknl
Created October 9, 2014 02:05
Show Gist options
  • Save mbrcknl/775bc638882656866301 to your computer and use it in GitHub Desktop.
Save mbrcknl/775bc638882656866301 to your computer and use it in GitHub Desktop.
{-# LANGUAGE Rank2Types #-}
type Lens s t a b = forall f. Functor f => (a -> f b) -> (s -> f t)
type Ref s t a b = s -> Rep a b t
data Rep a b t = Rep a (b -> t)
instance Functor (Rep a b) where
fmap f (Rep a g) = Rep a (f . g)
lens2Ref :: Lens s t a b -> Ref s t a b
lens2Ref r = r (\b -> Rep b id)
ref2Lens :: Ref s t a b -> Lens s t a b
ref2Lens l k x = case l x of
Rep s f -> fmap f (k s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment