Created
July 25, 2015 05:10
-
-
Save tokiwoousaka/0104d35348992082ff47 to your computer and use it in GitHub Desktop.
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
module Lib where | |
import Control.Lens | |
data Foo = Foo { a :: Int, b :: String, c :: Char } deriving Show | |
data Bar = Bar { x :: Int, y :: String } deriving Show | |
constructBar :: Lens Foo Foo Bar Bar | |
constructBar = lens getFoo2Bar setFooFromBar | |
getFoo2Bar :: Foo -> Bar | |
getFoo2Bar (Foo a b _) = Bar a b | |
setFooFromBar :: Foo -> Bar -> Foo | |
setFooFromBar (Foo _ _ c) (Bar a b) = Foo a b c | |
test :: IO () | |
test = do | |
let foo1 = Foo 100 "Hello" 'a' | |
let bar1 = Bar 200 "Lens" | |
print foo1 | |
print bar1 | |
print $ foo1^.constructBar | |
print $ foo1&constructBar.~bar1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment