Skip to content

Instantly share code, notes, and snippets.

@joshburgess
Forked from carymrobbins/LensLabels.hs
Created February 12, 2019 14:38
Show Gist options
  • Save joshburgess/d996e04fc0b9f925071b2edc641f90ea to your computer and use it in GitHub Desktop.
Save joshburgess/d996e04fc0b9f925071b2edc641f90ea to your computer and use it in GitHub Desktop.
Using labels as lenses with GHC 8
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE DeriveGeneric #-}
module LensLabels where
import Prelude
import Control.Lens
import Data.Generics.Labels
import GHC.Generics
main :: IO ()
main = do
putStrLn $ foo ^. #name
putStrLn $ bar ^. #name
print $ baz ^. #foo
putStrLn $ baz ^. #foo . #name
where
foo = Foo "hey"
bar = Bar "you"
baz = Baz foo
data Foo = Foo { name :: String } deriving (Show, Generic)
data Bar = Bar { name :: String } deriving (Show, Generic)
data Baz = Baz { foo :: Foo } deriving (Show, Generic)
dependencies:
- base >=4.7 && <5
- containers
- directory
- free
- lens
- generic-lens
- generic-lens-labels
- parsec
- semigroupoids
- transformers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment