Skip to content

Instantly share code, notes, and snippets.

@takaki takaki/gist:4595438
Created Jan 22, 2013

Embed
What would you like to do?
Data.Lens test
import Data.Lens.Common
data Hoge = Hoge {
x :: Int,
y :: Int,
z :: Int
} deriving(Show)
getX = x
getY = y
getZ = z
setX x h = h { x = x }
setY y h = h { y = y }
setZ z h = h { z = z }
xL = lens getX setX
yL = lens getY setY
zL = lens getZ setZ
main =
let h = Hoge { x = 3, y = 4, z = 5}
in do
putStrLn $ show $ getX h
putStrLn $ show $ h ^. xL
putStrLn $ show $ setX 10 h
putStrLn $ show $ (xL ^= 10) h
putStrLn $ show $ setX ((getX h) * 3) h
putStrLn $ show $ (xL ^%= (* 3)) h
putStrLn $ show $ (xL ^*= 3) h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.