stack-prism 0.1 → 0.1.1
raw patch · 6 files changed
+42/−19 lines, 6 filesdep ~basedep ~template-haskellnew-uploader
Dependency ranges changed: base, template-haskell
Files
- Data/StackPrism.hs +9/−5
- Data/StackPrism/Generic.hs +24/−8
- Data/StackPrism/TH.hs +7/−2
- ExampleGeneric.hs +0/−1
- ExampleTH.hs +0/−1
- stack-prism.cabal +2/−2
Data/StackPrism.hs view
@@ -21,7 +21,7 @@ -- | A stack prism is a bidirectional isomorphism that is partial in the backward direction. -- These prisms are compatible with the @lens@ library. ----- This can be used to express constructor-deconstructor pairs. For example:+-- Stack prisms can express constructor-deconstructor pairs. For example: -- -- > nil :: StackPrism t ([a] :- t) -- > nil = stackPrism f g@@ -39,11 +39,15 @@ -- -- 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. Representing constructor-destructor pairs as--- stack manipulators allows them to be composed more easily.+-- 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. ----- Modules "Data.StackPrism.Generic" and "Data.StackPrism.TH" offer generic ways of deriving @StackPrism@s for custom datatypes.-+-- 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.
Data/StackPrism/Generic.hs view
@@ -6,24 +6,40 @@ {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE RankNTypes #-} -module Data.StackPrism.Generic (StackPrisms, mkPrismList, PrismList(..), StackPrismLhs) where+module Data.StackPrism.Generic (+ -- * Deriving stack prisms+ mkPrismList, StackPrisms, PrismList(..), + -- * Re-exported types from "Data.StackPrism"+ StackPrism, (:-)(..)+ ) where+ import Data.StackPrism import GHC.Generics --- | Derive a list of stack prisms, one for each constructor in the 'Generic' datatype @a@. 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 @I@. These constructors are all exported by this module, but no documentation is generated for them by Hackage.------ 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]+-- | 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 mkPrismList = mkPrismList' to (Just . from) +-- | 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] data family PrismList (f :: * -> *) (a :: *) class MkPrismList (f :: * -> *) where
Data/StackPrism/TH.hs view
@@ -1,11 +1,16 @@ {-# LANGUAGE TypeOperators #-} {-# LANGUAGE TemplateHaskell #-} -module Data.StackPrism.TH (deriveStackPrisms, deriveStackPrismsWith, deriveStackPrismsFor) where+module Data.StackPrism.TH (+ -- * Deriving stack prisms+ deriveStackPrisms, deriveStackPrismsWith, deriveStackPrismsFor, + -- * Re-exported types from "Data.StackPrism"+ StackPrism, (:-)(..)+ ) where+ import Data.StackPrism import Language.Haskell.TH-import Control.Applicative import Control.Monad -- | Derive stack prisms for a given datatype.
ExampleGeneric.hs view
@@ -3,7 +3,6 @@ module Example where -import Data.StackPrism import Data.StackPrism.Generic import GHC.Generics
ExampleTH.hs view
@@ -2,7 +2,6 @@ module Example where -import Data.StackPrism import Data.StackPrism.TH
stack-prism.cabal view
@@ -1,5 +1,5 @@ Name: stack-prism-Version: 0.1+Version: 0.1.1 Synopsis: Stack prisms Description: Haskell lens prisms that use stack types @@ -30,7 +30,7 @@ profunctors >= 4.0 && < 5, tagged >= 0.4.4 && < 1, transformers >= 0.2 && < 0.5,- template-haskell >= 2.8 && < 2.10+ template-haskell >= 2.8 && < 2.11 Source-Repository head Type: git