Data.Transhare
Description
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.
- data TransResult a
- = Original {
- getTrans :: a
- | Transformed {
- getTrans :: a
- = Original {
- 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
Documentation
data TransResult a Source
Constructors
| Original | |
Fields
| |
| Transformed | |
Fields
| |
Instances
| Functor TransResult | |
| Applicative TransResult | |
| Transhare TransResult | |
| Eq a => Eq (TransResult a) | |
| Show a => Show (TransResult a) |
type TransR a = a -> TransResult aSource
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
fromO :: a -> TransResult a -> TransResult aSource