Question

data Foo = Foo {
  _bar :: Map String Integer
} deriving (Eq, Ord, Read, Show, Data, Typeable)

$(deriveSafeCopy 0 'base 'Foo)

$(makeLenses ''Foo)

Given the above code I am under the impression that it should be possible to do this:

addEntry :: String -> Update Foo ()
addEntry s = zoom bar $ modify $ insert s 0

But GHC will complain along the lines of:

src/Backend.hs:39:20:
    No instance for (Functor
                       (Control.Lens.Internal.Zoom.Zoomed (Update Foo) ()))

Any ideas?

Était-ce utile?

La solution

Control.Lens.Internal.Zoom.Zoomed is a type family which describes what kind of context is required during a zoom. It performs some special magic as you can see in the Control.Lens.Internal.Zoom module. Typically a user of zoom would never need to see that stuff so long as they zoom in on a "typical" monad transformer stack.

Update, while being implemented as just State beneath the covers, doesn't have a zoom instance. Its implementation is not exported either so you're unable to write your own, though it'd be quite trivial since Update doesn't use monad transformers.

type instance Zoomed (Update x) = Focusing Identity
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top