Created
March 16, 2018 21:35
-
-
Save carymrobbins/7346c7d9ec91ce9fca07dd58aec4f5f0 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