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

Elise Huard haskell at elisehuard.be
Mon Aug 18 13:17:11 UTC 2014


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


More information about the Beginners mailing list