Reputation: 2387
I'm slowly trying to wrap my head around how the lens
package works. I'm reading Edward's slides (http://comonad.com/haskell/Lenses-Folds-and-Traversals-NYC.pdf) and I have a question about the definition of Store s a
on slides 8 and 9:
newtype Lens s a = Lens (s -> Store s a)
data Store s a = Store (s -> a) s
Is the definition backwards? If lenses are pairs of getters and setters, it seems to me that Store s a
should be defined as:
data Store s a = Store (a -> s) a
where the first constructor parameter is the setter (put an a
and return the s
data structure) and the second is the getter (fetch the a
from the s
data structure).
Can anyone confirm if it's an error in the slides, or if my understanding is incorrect, please explain.
Thank you.
Upvotes: 1
Views: 227
Reputation: 8930
Yes, that looks like an error. But Store
is correct -- it's a standard comonad. The definition of Lens
should be newtype Lens s a = Lens (s -> Store a s)
.
Upvotes: 5