[Haskell-cafe] Lens with merge (Semigroup)

Tony Morris tonymorris at gmail.com
Mon Sep 5 09:19:22 CEST 2011

A regular Lens can be represented as follows:

data CoState a = CoState (a -> b) a

newtype Lens a b = Lens (a -> CoState b a)

I once read about a lens representation that permits a general "merge"
operation. I forget where I read it -- I think it was #haskell IRC.
However, as I recall, perhaps incorrectly, the merge operation involves
a Semigroup[1] and helps to overcome the fact that Lens is not an Arrow
and so does not have a (&&&) operation.

I am interested to know what this Lens operation is and the associated
merge operation.

-- Approximate
data SemigroupT f a = SemigroupT (a -> a -> f a)

Tony Morris

More information about the Haskell-Cafe mailing list