This module is my answer to the pattern discussed in http:blog.ezyang.com201106a-pattern-for-increasing-sharing about maximizing sharing when transforming an algebraic data type.
Transhare class is a kind of degerate case of
Traverse building on a new
data type called
TransResult defined below. The result
transM is a way to lift a
parsimonious transformer 'a -> Maybe a', which indicates identity with
Nothing, to work on a
container with maximized sharing.
- data TransResult a
- type TransM a = a -> Maybe a
- type TransR a = a -> TransResult a
- transMR :: TransM a -> TransR a
- transRM :: TransR a -> TransM a
- fromO :: a -> TransResult a -> TransResult a
- class Transhare f where
- transResult_laws :: Bool
TransR is a parsimonious transformer that returns (Original x) only if x is the original argument.
This must follow the law that TransMR . TransRM . t = t