
26 Nov
2007
26 Nov
'07
10:12 a.m.
On Mon, 26 Nov 2007, apfelmus wrote:
Benedikt Huber wrote:
type Upd a = a -> a data Ref cx t = Ref { select :: cx -> t , update :: Upd t -> Upd cx }
Functional references are also called "lens", I'm going to use that term from now on.
As a minor note, I somehow prefer a single primitive
data Lens s a = Lens { focus :: s -> (a, a -> s) }
put :: Lens s a -> a -> s -> s put x = flip $ snd . focus x
get :: Lens s a -> s -> a get x = fst . focus x
update :: Lens s a -> (a -> a) -> (s -> s) update x f s = let (a,g) = focus x s in g (f a)
I proposed something similar on http://www.haskell.org/haskellwiki/Record_access