-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Stack prisms -- -- Haskell lens prisms that use stack types @package stack-prism @version 0.1.6 module Data.StackPrism -- | A stack prism is a bidirectional isomorphism that is partial in the -- backward direction. These prisms are compatible with the lens -- library. -- -- Stack prisms can express constructor-deconstructor pairs. For example: -- --
-- nil :: StackPrism t ([a] :- t) -- nil = stackPrism f g -- where -- f t = [] :- t -- g ([] :- t) = Just t -- g _ = Nothing -- -- cons :: StackPrism (a :- [a] :- t) ([a] :- t) -- cons = stackPrism f g -- where -- f (x :- xs :- t) = (x : xs) :- t -- g ((x : xs) :- t) = Just (x :- xs :- t) -- g _ = Nothing ---- -- Here :- can be read as 'cons', forming a stack of values. For -- example, nil pushes [] onto the stack; or, in the -- backward direction, tries to remove [] from the stack. -- cons takes a head x and tail xs from the -- stack and pushes x : xs onto the stack, or, in the backward -- direction, tries to take x : xs from the stack and replaces -- it with its two individual components. -- -- Every constructor has its own stack prism version. You don't have to -- write them by hand; you can automatically generate them, either using -- Template Haskell (see module Data.StackPrism.TH) or using GHC -- generic programming (see module Data.StackPrism.Generic). type StackPrism a b = forall p f. (Choice p, Applicative f) => p a (f a) -> p b (f b) -- | Construct a prism. stackPrism :: (a -> b) -> (b -> Maybe a) -> StackPrism a b -- | Apply a prism in forward direction. forward :: StackPrism a b -> a -> b -- | Apply a prism in backward direction. backward :: StackPrism a b -> b -> Maybe a -- | Heterogenous stack with a head and a tail. Or: an infix way to write -- (,). data (:-) h t (:-) :: h -> t -> (:-) h t instance GHC.Base.Functor ((Data.StackPrism.:-) h) instance (GHC.Show.Show h, GHC.Show.Show t) => GHC.Show.Show (h Data.StackPrism.:- t) instance (GHC.Classes.Eq h, GHC.Classes.Eq t) => GHC.Classes.Eq (h Data.StackPrism.:- t) module Data.StackPrism.TH -- | Derive stack prisms for a given datatype. -- -- For example: -- --
-- deriveStackPrisms ''Maybe ---- -- will create -- --
-- _Just :: StackPrism (a :- t) (Maybe a :- t) -- _Nothing :: StackPrism t (Nothing :- t) ---- -- together with their implementations. deriveStackPrisms :: Name -> Q [Dec] -- | Derive stack prisms given a function that derives variable names from -- constructor names. deriveStackPrismsWith :: (String -> String) -> Name -> Q [Dec] -- | Derive stack prisms given a list of variable names, one for each -- constructor. deriveStackPrismsFor :: [String] -> Name -> Q [Dec] -- | A stack prism is a bidirectional isomorphism that is partial in the -- backward direction. These prisms are compatible with the lens -- library. -- -- Stack prisms can express constructor-deconstructor pairs. For example: -- --
-- nil :: StackPrism t ([a] :- t) -- nil = stackPrism f g -- where -- f t = [] :- t -- g ([] :- t) = Just t -- g _ = Nothing -- -- cons :: StackPrism (a :- [a] :- t) ([a] :- t) -- cons = stackPrism f g -- where -- f (x :- xs :- t) = (x : xs) :- t -- g ((x : xs) :- t) = Just (x :- xs :- t) -- g _ = Nothing ---- -- Here :- can be read as 'cons', forming a stack of values. For -- example, nil pushes [] onto the stack; or, in the -- backward direction, tries to remove [] from the stack. -- cons takes a head x and tail xs from the -- stack and pushes x : xs onto the stack, or, in the backward -- direction, tries to take x : xs from the stack and replaces -- it with its two individual components. -- -- Every constructor has its own stack prism version. You don't have to -- write them by hand; you can automatically generate them, either using -- Template Haskell (see module Data.StackPrism.TH) or using GHC -- generic programming (see module Data.StackPrism.Generic). type StackPrism a b = forall p f. (Choice p, Applicative f) => p a (f a) -> p b (f b) -- | Heterogenous stack with a head and a tail. Or: an infix way to write -- (,). data (:-) h t (:-) :: h -> t -> (:-) h t module Data.StackPrism.Generic -- | Derive a list of stack prisms. For more information on the shape of a -- PrismList, please see the documentation below. mkPrismList :: (Generic a, MkPrismList (Rep a)) => StackPrisms a -- | Convenient shorthand for a PrismList indexed by a type and its -- generic representation. type StackPrisms a = PrismList (Rep a) a -- | A data family that is indexed on the building blocks from -- representation types from GHC.Generics. It builds up to a -- list of prisms, one for each constructor in the generic -- representation. The list is wrapped in the unary constructor -- PrismList. Within that constructor, the prisms are separated -- by the right-associative binary infix constructor :&. -- Finally, the individual prisms are wrapped in the unary constructor -- P. -- -- As an example, here is how to define the prisms nil and -- cons for [a], which is an instance of -- Generic: -- --
-- nil :: StackPrism t ([a] :- t) -- cons :: StackPrism (a :- [a] :- t) ([a] :- t) -- PrismList (P nil :& P cons) = mkPrismList :: StackPrisms [a] ---- | A stack prism is a bidirectional isomorphism that is partial in the -- backward direction. These prisms are compatible with the lens -- library. -- -- Stack prisms can express constructor-deconstructor pairs. For example: -- --
-- nil :: StackPrism t ([a] :- t) -- nil = stackPrism f g -- where -- f t = [] :- t -- g ([] :- t) = Just t -- g _ = Nothing -- -- cons :: StackPrism (a :- [a] :- t) ([a] :- t) -- cons = stackPrism f g -- where -- f (x :- xs :- t) = (x : xs) :- t -- g ((x : xs) :- t) = Just (x :- xs :- t) -- g _ = Nothing ---- -- Here :- can be read as 'cons', forming a stack of values. For -- example, nil pushes [] onto the stack; or, in the -- backward direction, tries to remove [] from the stack. -- cons takes a head x and tail xs from the -- stack and pushes x : xs onto the stack, or, in the backward -- direction, tries to take x : xs from the stack and replaces -- it with its two individual components. -- -- Every constructor has its own stack prism version. You don't have to -- write them by hand; you can automatically generate them, either using -- Template Haskell (see module Data.StackPrism.TH) or using GHC -- generic programming (see module Data.StackPrism.Generic). type StackPrism a b = forall p f. (Choice p, Applicative f) => p a (f a) -> p b (f b) -- | Heterogenous stack with a head and a tail. Or: an infix way to write -- (,). data (:-) h t (:-) :: h -> t -> (:-) h t instance Data.StackPrism.Generic.MkPrismList f => Data.StackPrism.Generic.MkPrismList (GHC.Generics.M1 GHC.Generics.D c f) instance (Data.StackPrism.Generic.MkPrismList f, Data.StackPrism.Generic.MkPrismList g) => Data.StackPrism.Generic.MkPrismList (f GHC.Generics.:+: g) instance Data.StackPrism.Generic.MkStackPrism f => Data.StackPrism.Generic.MkPrismList (GHC.Generics.M1 GHC.Generics.C c f) instance Data.StackPrism.Generic.MkStackPrism GHC.Generics.U1 instance Data.StackPrism.Generic.MkStackPrism (GHC.Generics.K1 i a) instance Data.StackPrism.Generic.MkStackPrism f => Data.StackPrism.Generic.MkStackPrism (GHC.Generics.M1 i c f) instance (Data.StackPrism.Generic.MkStackPrism f, Data.StackPrism.Generic.MkStackPrism g) => Data.StackPrism.Generic.MkStackPrism (f GHC.Generics.:*: g)