-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A library to apply transformation to containers so as to maximize sharing of unchanged subcomponents. -- -- A library to apply transformation to containers so as to maximize -- sharing of unchanged subcomponents. @package Transhare @version 0.9 -- | 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. -- -- The' Transhare class is a kind of degerate case of -- Traverse building on a new Applicative 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. module Data.Transhare data TransResult a Original :: a -> TransResult a getTrans :: TransResult a -> a Transformed :: a -> TransResult a getTrans :: TransResult a -> a -- | TransM is a parsimonious transformer that can return -- Nothing when the transformation is an identity. -- -- If the result is Just t then the result t -- might or might not be identical to the argument. type TransM a = a -> Maybe a -- | 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 -- -- The disadvantage of TransR compared to TransM is -- ensuring the above law and that sharing for Original results is -- actually being done. -- -- TransR which implement sharing correctly are proper -- implementations of TransR type TransR a = a -> TransResult a -- | transMR creates a proper implementation of transR from -- any transM transMR :: TransM a -> TransR a -- | transRM creates a proper implementation of transM only -- from a proper implementation of transR transRM :: TransR a -> TransM a -- | fromO is a helper function used with Applicative to ensure the -- TransR computed by transR are proper implementations. fromO :: a -> TransResult a -> TransResult a class Transhare f transM :: Transhare f => TransM a -> TransM (f a) transR :: Transhare f => TransR a -> TransR (f a) transResult_laws :: Bool instance Show a => Show (TransResult a) instance Eq a => Eq (TransResult a) instance Transhare TransResult instance Transhare Tree instance Transhare [] instance Transhare (Either a) instance Transhare ((,) a) instance Applicative TransResult instance Functor TransResult