A
SimpleGetter s a extracts
a from
s; so,
it's the same thing as
(s -> a), but you can use it in
lens chains because its type looks like this:
type SimpleGetter s a =
forall r. (a -> Const r a) -> s -> Const r s
Since
Const r is a functor,
SimpleGetter has the same
shape as other lens types and can be composed with them. To get
(s
-> a) out of a
SimpleGetter, choose
r ~ a and
feed
Const :: a -> Const a a to the getter:
-- the actual signature is more permissive:
-- view :: Getting a s a -> s -> a
view :: SimpleGetter s a -> s -> a
view getter = getConst . getter Const
The actual
Getter from lens is more general:
type Getter s a =
forall f. (Contravariant f, Functor f) => (a -> f a) -> s -> f s
I'm not currently aware of any functions that take lens's
Getter but won't accept
SimpleGetter, but you should
try to avoid exporting
SimpleGetters anyway to minimise
confusion. Alternatively, look at
microlens-contra, which
provides a fully lens-compatible
Getter.
Lens users: you can convert a
SimpleGetter to
Getter
by applying
to . view to it.