-
-
Save joshburgess/d996e04fc0b9f925071b2edc641f90ea to your computer and use it in GitHub Desktop.
Using labels as lenses with GHC 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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