Skip to content

Instantly share code, notes, and snippets.

@bananu7
Created October 11, 2013 15:35
Show Gist options
  • Save bananu7/6936855 to your computer and use it in GitHub Desktop.
Save bananu7/6936855 to your computer and use it in GitHub Desktop.
{-# LANGUAGE TemplateHaskell, Rank2Types #-}
import Prelude hiding ((.), id)
import Control.Category
import Control.Lens
import Control.Lens.TH
type Register = Int
data Machine = Machine { _ax :: Register, _bx :: Register } deriving Show
data SMPMachine = SMP { _cpu0 :: Machine, _cpu1 :: Machine } deriving Show
makeLenses ''Machine
makeLenses ''SMPMachine
mov :: Lens' m r -> Lens' m r -> m -> m
mov from to m = set to (m ^. from) m
main = do
let m = Machine 42 69
putStrLn $ show m
let m' = mov ax bx m
putStrLn $ show m'
let s = SMP (Machine 22 0) (Machine 99 11)
putStrLn $ show s
let s' = mov (cpu0.ax) (cpu1.bx) s
putStrLn $ show s'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment