Skip to content

Instantly share code, notes, and snippets.

@ktvoelker
Created August 1, 2010 17:42
Show Gist options
  • Save ktvoelker/503567 to your computer and use it in GitHub Desktop.
Save ktvoelker/503567 to your computer and use it in GitHub Desktop.
data Foo = Foo { foo :: Int }
x0 = Foo { foo = 3 } -- create
x1 = x0 { foo = 4 } -- replace
x2 = foo x1 -- access
x3 = x1 { foo = foo x1 + 1 } -- apply
upd :: Name -> Q Exp
x3 = $(upd 'foo) (+ 1) x1
old :: State Foo ()
old = modify (\x -> x { foo = foo x + 1 })
new :: State Foo ()
new = modify $ $(upd 'foo) (+ 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment