ekmett/lens — pull request #257 by mikeplus64 (2013-01-20 13:12:09+00:00)
Title: Lenses with the same names

One of the most ran-into pitfalls of Haskell records is that two records can't have the same field names. The same doesn't have to go for lenses though!

Minimal example:
```haskell
{-# LANGUAGE TemplateHaskell, FunctionalDependencies #-}
import Control.Lens

data Pos0 = Pos0 { _Pos0_x, _Pos0_y :: Int } deriving Show
data Pos1 = Pos1 { _Pos1_x, _Pos1_y :: Double } deriving Show

makeClassier ''Pos0
makeClassier ''Pos1
{- Generating (in addition to "normal" lenses being generated):
class Has_x c e | c -> e where
x :: Lens' c e
instance Has_x Pos0 Int where
{-# INLINE x #-}
x = _Pos0_x_lens
class Has_y c e | c -> e where
y :: Lens' c e
instance Has_y Pos0 Int where
{-# INLINE y #-}
y = _Pos0_y_lens

instance Has_x Pos1 Double where
{-# INLINE x #-}
x = _Pos1_x_lens
instance Has_y Pos1 Double where
{-# INLINE y #-}
y = _Pos1_y_lens
-}

main :: IO ()
main = do
let pos0 = Pos0 0 0
pos1 = Pos1 0 0

print (pos0^.x, pos0^.y)
print (pos1^.x, pos1^.y)

print (x .~ 423.5 $ pos1, y .~ 456.034 $ pos1)

print $ pos0
& x %~ succ
& y %~ pred
```