addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramlinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Hoodlums Message Board › Homework: Lenses

Homework: Lenses

Peter M.
Group Organizer
London, GB
Post #: 54
At this month's session, we looked at lenses. I've posted the code here. We developed a simple lenses pairing an accessor and a modifier function, and we looked at lenses built on the Store comonad and at van Laarhoven lenses. To help us understand these alternative implementations, I thought I'd set a homework on them.

The type of van Laarhoven lenses is:

> type Lens s a = forall f. Functor f => (a -> f a) -> s -> f s

1. Write the functions (^.), (^=) and (%=).

2. Write functions to convert from our simple lenses to van Laarhoven lenses and vice-versa.

Avoiding the use of Store from Control.Comonad, we can also define:

> newtype Lens s a = s -> (a -> s, a)

3. Write the functions (^.), (^=) and (%=), and the Category instance.

4. Write functions to convert from our simple lenses to these lenses and vice-versa.

The fact that we can write these functions to convert both ways shows that these types are isomorphic. Those who attended Chris Taylor's excellent talk The Algebra of Algebraic Data Types, may want to try:

5. Show how each of these types are algebraically equivalent.
Stephanie R.
user 216833657
London, GB
Post #: 1
thanks for sharing..indeed an interesting session..and it's helped me a lot with physics paper so that I didn't have to use Online Homework Service..and that's great news to me
Powered by mvnForum

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy