
Hello, I have this newtype: newtype Awesome a = Awesome (StateT AwesomeState (ExceptT B.ByteString IO) a) deriving (Functor, Applicative, Monad, MonadIO, MonadError B.ByteString, MonadState AwesomeState) AwesomeState is quite deeply nested record. I'm using lens package in my project and can use some basic primitives from that package. But today I read about 'zoom' from lens package and think it might help me write my code a bit faster and cleaner. Right now if I try to update something deeply nested in my state I do it by hand (pseudocode follows): smth <- use $ myState.thisField.otherField myState.thisField.otherField .= smth { _someProperty = "aaa", _otherThing = (smth^.otherThing) { _hereIsSomethingElse = 2 } } and so on. I hope you get the picture. Now I though with zooming I would be able to do it more easily: zoom (myState.thisField.OtherField) $ do someProperty .= "aaa" otherThing.hereIsSomethingElse .= 2 But the problem is that if I try to use zoom I get an error message which I do not understand how to handle. Tried to search for information but couldn't get anything that I could understand (just found a single stackoverflow question which didn't clear it enough for me). The error message: Couldn't match type ‘Control.Lens.Internal.Zoom.Zoomed Awesome’ with ‘Control.Lens.Internal.Zoom.Zoomed m0’ Anyone could suggest what it is that I need to do to be able to use 'zoom'? Best regards, Konstantin Saveljev

Hello, Well, to properly implement zoom, you'd have to use a similar approach to http://hackage.haskell.org/package/lens-4.8/docs/Control-Lens-Internal-Zoom.... and implement the Zoom type class. Perhaps try implementing http://hackage.haskell.org/package/mmorph-1.0.4/docs/Control-Monad-Morph.htm... and use (hoist $ zoom whatever) instead? Best regards, Marcin Mrotek
participants (2)
-
Konstantin Saveljev
-
Marcin Mrotek