[Haskell-beginners] Lens: zooming

Konstantin Saveljev konstantin.saveljev at gmail.com
Wed Apr 1 21:11:58 UTC 2015


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150402/68bce9a3/attachment.html>


More information about the Beginners mailing list