title: Haskell Control.Lens Traversing Prism
body: <p>I have a deeply nested data structure, and I'm using Control.Lens.* to simplify accessing its values in a state monad.</p>
  
  <p>So consider the following:</p>
  
  <pre><code>data Config = Config { _foo :: Maybe Int
                       , _bar :: Int
                       }
  
  $(makeLenses ''Config)
  </code></pre>
  
  <p>How do I operate "functorially" over the Maybe?  I'd like to write an idiomatic getter that does:</p>
  
  <pre><code>config = Config (Just 1) 0
  config^.foo.to fmap (+1) == Just 2
  </code></pre>
  
  <p>Better still, how would we handle the case when Config is nested deeper?</p>
  
  <pre><code>data Config = { _foo :: Maybe Foo }
  data Foo = Foo { _bar :: Bar }
  data Bar = Bar Int
  $(makeLenses ''Bar)
  $(makeLenses ''Foo)
  </code></pre>
  
  <p>Can we use the accessors foo and bar to Maybe return a modified Bar?</p>