Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Lens: zooming (Konstantin Saveljev)
2. Re: Lens: zooming (Marcin Mrotek)
----------------------------------------------------------------------
Message: 1
Date: Thu, 2 Apr 2015 00:11:58 +0300
From: Konstantin Saveljev <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Lens: zooming
Message-ID:
<cakncejo2hpub8zwvso6qu+udheelwhur4cw1xxm2yvf+0sf...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
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-0001.html>
------------------------------
Message: 2
Date: Wed, 1 Apr 2015 23:44:38 +0200
From: Marcin Mrotek <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Lens: zooming
Message-ID:
<CAJcfPzmS-TLvHQex8tLnqd32h9M4NbwTh3=zewhqhzmake2...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
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.html
and implement the Zoom type class. Perhaps try implementing
http://hackage.haskell.org/package/mmorph-1.0.4/docs/Control-Monad-Morph.html
and use (hoist $ zoom whatever) instead?
Best regards,
Marcin Mrotek
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 82, Issue 3
****************************************