Safe Haskell | None |
---|---|
Language | Haskell2010 |
The HasStack monad used in MIMO to construct lenses that look deep into a record type. However, it does not involve the Path type mechanism, and is unaware of View instances and other things that modify the type graph. Lets see how it adapts.
- class Monad m => HasStack m where
- newtype Wrapper a = Wrapper a
- unwrap :: forall a a. Iso (Wrapper a) (Wrapper a) a a
- data StackElement = StackElement FieldType Con Dec
- prettyStack :: [StackElement] -> String
- foldField :: HasStack m => (FieldType -> m r) -> Dec -> Con -> FieldType -> m r
- type StackT m = ReaderT [StackElement] m
- execStackT :: Monad m => StackT m a -> m a
- stackAccessor :: (Quasi m, HasStack m) => ExpQ -> Type -> m Exp
- makeLenses' :: (Type -> Q (Set Type)) -> [Name] -> Q [Dec]
- traceIndented :: HasStack m => String -> m ()
Documentation
class Monad m => HasStack m where Source
withStack :: ([StackElement] -> m a) -> m a Source
Quasi m => HasStack (ReaderT [StackElement] m) Source | |
HasStack m => HasStack (ReaderT (Wrapper a) m) Source | |
Monad m => HasStack (ReaderT TypeGraph m) Source | |
HasStack m => HasStack (StateT s m) Source | |
(HasStack m, Monoid w) => HasStack (WriterT w m) Source | |
(Quasi m, Monoid w) => HasStack (RWST [StackElement] w s m) Source |
data StackElement Source
The information required to extact a field value from a value. We keep a stack of these as we traverse a declaration. Generally, we only need the field names.
Eq StackElement Source | |
Data StackElement Source | |
Show StackElement Source | |
Quasi m => HasStack (ReaderT [StackElement] m) Source | |
(Quasi m, Monoid w) => HasStack (RWST [StackElement] w s m) Source |
prettyStack :: [StackElement] -> String Source
foldField :: HasStack m => (FieldType -> m r) -> Dec -> Con -> FieldType -> m r Source
Push the stack and process the field.
Stack+instance map monad
type StackT m = ReaderT [StackElement] m Source
execStackT :: Monad m => StackT m a -> m a Source
Stack operations
stackAccessor :: (Quasi m, HasStack m) => ExpQ -> Type -> m Exp Source
Re-implementation of stack accessor in terms of stackLens
makeLenses' :: (Type -> Q (Set Type)) -> [Name] -> Q [Dec] Source
Generate lenses to access the fields of the row types. Like Control.Lens.TH.makeLenses, but makes lenses for every field, and instead of removing the prefix '_' to form the lens name it adds the prefix "lens" and capitalizes the first letter of the field. The only reason for this function is backwards compatibility, the fields should be changed so they begin with _ and the regular makeLenses should be used.
traceIndented :: HasStack m => String -> m () Source