[Haskell-beginners] Using Traversal as a kind of pointer

Benjamin Edwards edwards.benj at gmail.com
Mon Aug 18 13:31:26 UTC 2014


And just remember filtered is only a valid traversal if you don't change
the number of targets with the modification function!


On 18 August 2014 14:17, Elise Huard <haskell at elisehuard.be> wrote:

> Hi Daniel,
>
> thanks for your answer. That looks like something that might work -
> however,  having never worked with Optics, I'm not entirely sure
> whether I'm doing it right, getting an error:
> *Main Graphics.Rendering.OpenGL Control.Lens> :t (liveforms . filtered
> (colliding p))
>
> <interactive>:1:14:
>     Couldn't match type _Lifeform_ with _[Lifeform]_
>     Expected type: (Lifeform -> f Lifeform)
>                    -> [Lifeform] -> f [Lifeform]
>       Actual type: Optic' (->) f Lifeform Lifeform
>     In the second argument of _(.)_, namely
>       _filtered ((flip colliding) p)_
>     In the expression: (liveforms . filtered ((flip colliding) p))
> *Main Graphics.Rendering.OpenGL Control.Lens>
>
> Also, may I ask what the '&' is in your proposed solution?
> Thanks,
>
> Elise
>
> On 18 August 2014 13:30, Daniel Trstenjak <daniel.trstenjak at gmail.com>
> wrote:
> >
> > Hi Elise,
> >
> > I'm not quite sure if I completely understood your use case, but if
> > you only want to modify the lifeforms that are colliding with the player,
> > then you could have something like:
> >
> >    world & liveforms . filtered (collidingWith player) %~ \liveform ->
> ...
> >
> > with
> >
> >    liveforms :: Lens' World [Lifeform]
> >
> >    collidingWith :: Player -> Lifeform -> Bool
> >
> >
> > I would consider this as a quite nice solution.
> >
> >
> > Greetings,
> > Daniel
> > _______________________________________________
> > Beginners mailing list
> > Beginners at haskell.org
> > http://www.haskell.org/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140818/ae439108/attachment.html>


More information about the Beginners mailing list