Skip to content

Instantly share code, notes, and snippets.

@Porges
Created August 4, 2017 06:10
Show Gist options
  • Save Porges/85f66298fcedb59f834b19884778e524 to your computer and use it in GitHub Desktop.
Save Porges/85f66298fcedb59f834b19884778e524 to your computer and use it in GitHub Desktop.
Ed's "pseudo-haskell" from http://comonad.com/reader/2012/mirrored-lenses/ is now compilable?
{-# LANGUAGE RankNTypes, PolyKinds, TupleSections, TypeFamilies, TypeFamilyDependencies #-}
import Data.Kind (Type)
type LensFamily (outer :: t -> Type) (inner :: t -> Type) =
forall a b f. Functor f => (inner a -> f (inner b)) -> (outer a -> f (outer b))
type family Snd b a = r | r -> b a where Snd b a = (a, b)
type family Fst a b = r | r -> a b where Fst a b = (a, b)
type family Id t = r | r -> t where Id x = x
fstLens :: LensFamily (Snd b) Id
fstLens f (a, b) = (, b) <$> f a
sndLens :: LensFamily (Fst a) Id
sndLens f (a, b) = (a, ) <$> f b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment