Created
October 11, 2013 15:35
-
-
Save bananu7/6936855 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
{-# 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