Permalink
Browse files

Changed type variable e to v everywhere.

  • Loading branch information...
mightybyte committed Aug 1, 2011
1 parent 391e94f commit b8a1e4fdea2dc034fa743c289ba76f12382c6e7b
View
@@ -34,23 +34,23 @@ not conceptually mutable in the same way as the actual state, it is stored in
the reader environment. The state monad part is used for the top level state
b, giving is the following newtype.
-newtype LensT b e s m a = LensT (RST (b :-> e) s m a)
+newtype LensT b v s m a = LensT (RST (b :-> v) s m a)
-LensT comes with a (MonadReader (b :-> e)) instance for retrieving the lens
-and a (MonadState e) instance that uses the lens transparently to achieve
-stateful behavior with the type e. From here the definition of Handler is
+LensT comes with a (MonadReader (b :-> v)) instance for retrieving the lens
+and a (MonadState v) instance that uses the lens transparently to achieve
+stateful behavior with the type v. From here the definition of Handler is
fairly natural:
-newtype Handler b e a =
- Handler (LensT (Snaplet b) (Snaplet e) (Snaplet b) Snap a)
+newtype Handler b v a =
+ Handler (LensT (Snaplet b) (Snaplet v) (Snaplet b) Snap a)
-We use "LensT (Snaplet b) (Snaplet e)" instead of "LensT b (Snaplet e)"
+We use "LensT (Snaplet b) (Snaplet v)" instead of "LensT b (Snaplet v)"
because it is desirable to be able to use the identity lens to construct a
"Handler b b". The only issue with this formulation is that the lens
manipulation functions provided by LensT are not what the end user needs. The
-end user has a lens of type (b :-> Snaplet e) created by the mkLabels
+end user has a lens of type (b :-> Snaplet v) created by the mkLabels
function. But LensT's downcast and withLens functions need (Snaplet b :->
-Snaplet e) lenses. These can be derived easily by composing the user-supplied
+Snaplet v) lenses. These can be derived easily by composing the user-supplied
lens with the internal lens (Snaplet a :-> a) derived from the definition of
the Snaplet data structure.
@@ -90,10 +90,10 @@ The Heist snaplet is a fairly complex snaplet that illustrates a number of
concepts that you may encounter while writing your own snaplets. The biggest
issue arises because Heist's TemplateState is parameterized by the handler
monad. This means that if you want to do something like a wih transformation
-with a lens (b :-> e) you will naturally want to apply the same transformation
+with a lens (b :-> v) you will naturally want to apply the same transformation
to the Handler parameter of the TemplateState. Unfortunately, due to Heist's
design, this is computationally intensive, must be performed at runtime, and
-requires that you have a bijection (b :<->: e). To avoid this issue, we only
+requires that you have a bijection (b :<->: v). To avoid this issue, we only
use the base application state, (TemplateState (Handler b b)).
The basic functions for manipulating templates are not affected by this
@@ -118,8 +118,8 @@ look something like this:
instance HasHeist App App where
heistLens = subSnaplet heist
-The call to subSnaplet is required because HasHeist needs a lens (Snaplet e
-:-> Snaplet (Heist b)) instead of the lens (e :-> Snaplet (Heist b)) that
+The call to subSnaplet is required because HasHeist needs a lens (Snaplet v
+:-> Snaplet (Heist b)) instead of the lens (v :-> Snaplet (Heist b)) that
you willll get from mkLabels. We did it this way because it allows us to make
a default instance using the id function from Control.Category.
View
@@ -187,10 +187,10 @@ import Snap.Snaplet.Internal.Types
--
-- Several monads use this infrastructure. These monads need at least three type
-- parameters. Two for the lens type, and the standard 'a' denoting the monad
--- return value. You will usually see this written in type signatures as "m b e a"
+-- return value. You will usually see this written in type signatures as "m b v a"
-- or some variation. The 'm' is the type variable of the MonadSnaplet type class.
--- 'b' is the base state, and 'e' is the state of the current snaplet (or simply,
--- current state).
+-- 'b' is the base state, and 'v' is the state of the current "view" snaplet (or
+-- simply, current state).
--
-- The MonadSnaplet type class distills the essence of the operations used
-- with this pattern. Its functions define fundamental methods for navigating
@@ -213,7 +213,7 @@ import Snap.Snaplet.Internal.Types
--
-- In order for a snaplet to initialize its state, it needs to initialize all
-- of its subsnaplets. Every snaplet will have an initializer with a return
--- type of @Initializer b e (Snaplet a)@ where 'a' is the snaplet's state.
+-- type of @Initializer b v (Snaplet a)@ where 'a' is the snaplet's state.
-- You must call these initializer functions wrapped in a call to
-- 'nestSnaplet'.
@@ -227,7 +227,7 @@ import Snap.Snaplet.Internal.Types
-- $writingSnaplets
-- When writing a snaplet, you must define an initializer function. The
-- initializer function for the Foo snaplet (where Foo is the snaplet's
--- state type) must have a return type of @Initializer b e (Snaplet Foo)@.
+-- state type) must have a return type of @Initializer b v (Snaplet Foo)@.
-- To create an initializer like this, you have to use the 'makeSnaplet'
-- function. It takes care of the necessary internal bookkeeping needed when
-- initializing a new snaplet. Haskell's strong type system allows us to
View
@@ -79,11 +79,11 @@ import Snap.Snaplet.HeistNoClass (Heist, heistInit, clearHeistCache)
-- > h <- nestSnaplet "heist" $ heistInit "templates"
-- > addSplices myAppSplices
-- > return $ App h
-class HasHeist b e where
- -- | A lens from e to the Heist snaplet. The b parameter to Heist will
+class HasHeist b v where
+ -- | A lens from v to the Heist snaplet. The b parameter to Heist will
-- typically be the base state of your application. Most of the time
- -- 'b' and 'e' will be the same.
- heistLens :: Snaplet e :-> Snaplet (Heist b)
+ -- 'b' and 'v' will be the same.
+ heistLens :: Snaplet v :-> Snaplet (Heist b)
------------------------------------------------------------------------------
@@ -103,21 +103,21 @@ instance HasHeist b (Heist b) where heistLens = id
-- | Adds templates to the Heist TemplateState. Other snaplets should use
-- this function to add their own templates. The templates are automatically
-- read from the templates directory in the current snaplet's filesystem root.
-addTemplates :: HasHeist b b => ByteString -> Initializer b e ()
+addTemplates :: HasHeist b b => ByteString -> Initializer b v ()
addTemplates pfx = withTop' heistLens (Unclassed.addTemplates pfx)
------------------------------------------------------------------------------
-- | Adds templates to the Heist TemplateState, and lets you specify where
-- they are fonud in the filesystem.
-addTemplatesAt :: HasHeist b b => ByteString -> FilePath -> Initializer b e ()
+addTemplatesAt :: HasHeist b b => ByteString -> FilePath -> Initializer b v ()
addTemplatesAt pfx p = withTop' heistLens (Unclassed.addTemplatesAt pfx p)
------------------------------------------------------------------------------
-- | Allows snaplets to add splices.
addSplices :: (HasHeist b b)
- => [(Text, Unclassed.SnapletSplice b e)] -> Initializer b e ()
+ => [(Text, Unclassed.SnapletSplice b v)] -> Initializer b v ()
addSplices = Unclassed.addSplices' heistLens
@@ -129,28 +129,28 @@ addSplices = Unclassed.addSplices' heistLens
------------------------------------------------------------------------------
-- | Renders a template as text\/html. If the given template is not found,
-- this returns 'empty'.
-render :: HasHeist b b => ByteString -> Handler b e ()
+render :: HasHeist b b => ByteString -> Handler b v ()
render t = withTop' heistLens (Unclassed.render t)
------------------------------------------------------------------------------
-- | Renders a template as the given content type. If the given template
-- is not found, this returns 'empty'.
-renderAs :: HasHeist b b => ByteString -> ByteString -> Handler b e ()
+renderAs :: HasHeist b b => ByteString -> ByteString -> Handler b v ()
renderAs ct t = withTop' heistLens (Unclassed.renderAs ct t)
------------------------------------------------------------------------------
-- | Analogous to 'fileServe'. If the template specified in the request path
-- is not found, it returns 'empty'.
-heistServe :: HasHeist b b => Handler b e ()
+heistServe :: HasHeist b b => Handler b v ()
heistServe = withTop' heistLens Unclassed.heistServe
------------------------------------------------------------------------------
-- | Analogous to 'fileServeSingle'. If the given template is not found,
-- this throws an error.
-heistServeSingle :: HasHeist b b => ByteString -> Handler b e ()
+heistServeSingle :: HasHeist b b => ByteString -> Handler b v ()
heistServeSingle t = withTop' heistLens (Unclassed.heistServeSingle t)
@@ -159,18 +159,18 @@ heistServeSingle t = withTop' heistLens (Unclassed.heistServeSingle t)
-- a common combination of heistLocal, bindSplices, and render.
renderWithSplices :: HasHeist b b
=> ByteString
- -> [(Text, Unclassed.SnapletSplice b e)]
- -> Handler b e ()
+ -> [(Text, Unclassed.SnapletSplice b v)]
+ -> Handler b v ()
renderWithSplices = Unclassed.renderWithSplices' heistLens
------------------------------------------------------------------------------
-- | Runs an action with additional splices bound into the Heist
-- 'TemplateState'.
withSplices :: HasHeist b b
- => [(Text, Unclassed.SnapletSplice b e)]
- -> Handler b e a
- -> Handler b e a
+ => [(Text, Unclassed.SnapletSplice b v)]
+ -> Handler b v a
+ -> Handler b v a
withSplices = Unclassed.withSplices' heistLens
@@ -182,8 +182,8 @@ withSplices = Unclassed.withSplices' heistLens
-- > heistLocal (bindSplices mySplices) handlerThatNeedsSplices
heistLocal :: HasHeist b b
=> (TemplateState (Handler b b) -> TemplateState (Handler b b))
- -> Handler b e a
- -> Handler b e a
+ -> Handler b v a
+ -> Handler b v a
heistLocal = Unclassed.heistLocal' heistLens
@@ -193,7 +193,7 @@ heistLocal = Unclassed.heistLocal' heistLens
-- The reasons for this are beyond the scope of this discussion, but the
-- result is that 'lift' inside a splice only works with @Handler b b@
-- actions. When you're writing your own snaplets you obviously would rather
--- work with @Handler b e@ so your local snaplet's state is available. We
+-- work with @Handler b v@ so your local snaplet's state is available. We
-- provide the SnapletHeist monad to make this possible. The general rule is
-- that when you're using Snaplets and Heist, use SnapletHeist instead of
-- HeistT (previously called TemplateMonad) and use SnapletSplice instead of
@@ -94,56 +94,56 @@ clearHeistCache = clearCacheTagState . _heistCTS
------------------------------------------------------------------------------
-- |
-newtype SnapletHeist b e a = SnapletHeist
- (ReaderT (Snaplet b :-> Snaplet e) (HeistT (Handler b b)) a)
+newtype SnapletHeist b v a = SnapletHeist
+ (ReaderT (Snaplet b :-> Snaplet v) (HeistT (Handler b b)) a)
deriving ( Monad
, Functor
, Applicative
, Alternative
, MonadIO
, MonadPlus
- , MonadReader (Snaplet b :-> Snaplet e)
+ , MonadReader (Snaplet b :-> Snaplet v)
)
-type SnapletSplice b e = SnapletHeist b e Template
+type SnapletSplice b v = SnapletHeist b v Template
------------------------------------------------------------------------------
-- | Runs the SnapletSplice.
-runSnapletSplice :: (Snaplet b :-> Snaplet e)
- -> SnapletHeist b e a
+runSnapletSplice :: (Snaplet b :-> Snaplet v)
+ -> SnapletHeist b v a
-> HeistT (Handler b b) a
runSnapletSplice l (SnapletHeist m) = runReaderT m l
-withSS :: ((Snaplet b :-> Snaplet e) -> (Snaplet b :-> Snaplet e'))
- -> SnapletHeist b e' a
- -> SnapletHeist b e a
+withSS :: ((Snaplet b :-> Snaplet v) -> (Snaplet b :-> Snaplet v'))
+ -> SnapletHeist b v' a
+ -> SnapletHeist b v a
withSS f (SnapletHeist m) = SnapletHeist $ withReaderT f m
------------------------------------------------------------------------------
-- | Lifts a HeistT action into SnapletHeist.
-liftHeist :: HeistT (Handler b b) a -> SnapletHeist b e a
+liftHeist :: HeistT (Handler b b) a -> SnapletHeist b v a
liftHeist = SnapletHeist . lift
------------------------------------------------------------------------------
-- | Lifts a Handler into SnapletHeist.
-liftHandler :: Handler b b a -> SnapletHeist b e a
+liftHandler :: Handler b b a -> SnapletHeist b v a
liftHandler = liftHeist . lift
------------------------------------------------------------------------------
-- | Common idiom for the combination of liftHandler and withTop.
-liftWith :: (Snaplet b :-> Snaplet e')
- -> Handler b e' a
- -> SnapletHeist b e a
+liftWith :: (Snaplet b :-> Snaplet v')
+ -> Handler b v' a
+ -> SnapletHeist b v a
liftWith l = liftHandler . withTop' l
-instance MonadState e (SnapletHeist b e) where
+instance MonadState v (SnapletHeist b v) where
get = do
l <- ask
b <- liftHandler lhGet
@@ -168,8 +168,8 @@ instance MonadSnaplet SnapletHeist where
------------------------------------------------------------------------------
-- | SnapletSplices version of bindSplices.
-bindSnapletSplices :: (Snaplet b :-> Snaplet e)
- -> [(Text, SnapletSplice b e)]
+bindSnapletSplices :: (Snaplet b :-> Snaplet v)
+ -> [(Text, SnapletSplice b v)]
-> TemplateState (Handler b b)
-> TemplateState (Handler b b)
bindSnapletSplices l splices =
@@ -212,17 +212,17 @@ addTemplatesAt urlPrefix templateDir = do
addSplices' :: (Snaplet b :-> Snaplet (Heist b))
- -> [(Text, SnapletSplice b e)]
- -> Initializer b e ()
+ -> [(Text, SnapletSplice b v)]
+ -> Initializer b v ()
addSplices' heist splices = do
_lens <- getLens
withTop' heist $ addPostInitHook $
return . changeTS (bindSnapletSplices _lens splices)
addSplices :: (b :-> Snaplet (Heist b))
- -> [(Text, SnapletSplice b e)]
- -> Initializer b e ()
+ -> [(Text, SnapletSplice b v)]
+ -> Initializer b v ()
addSplices heist splices = addSplices' (subSnaplet heist) splices
@@ -272,8 +272,8 @@ heistServeSingle t =
heistLocal' :: (Snaplet b :-> Snaplet (Heist b))
-> (TemplateState (Handler b b) -> TemplateState (Handler b b))
- -> Handler b e a
- -> Handler b e a
+ -> Handler b v a
+ -> Handler b v a
heistLocal' heist f m = do
hs <- withTop' heist $ get
withTop' heist $ modify $ changeTS f
@@ -284,39 +284,39 @@ heistLocal' heist f m = do
heistLocal :: (b :-> Snaplet (Heist b))
-> (TemplateState (Handler b b) -> TemplateState (Handler b b))
- -> Handler b e a
- -> Handler b e a
+ -> Handler b v a
+ -> Handler b v a
heistLocal heist f m = heistLocal' (subSnaplet heist) f m
withSplices' :: (Snaplet b :-> Snaplet (Heist b))
- -> [(Text, SnapletSplice b e)]
- -> Handler b e a
- -> Handler b e a
+ -> [(Text, SnapletSplice b v)]
+ -> Handler b v a
+ -> Handler b v a
withSplices' heist splices m = do
_lens <- getLens
heistLocal' heist (bindSnapletSplices _lens splices) m
withSplices :: (b :-> Snaplet (Heist b))
- -> [(Text, SnapletSplice b e)]
- -> Handler b e a
- -> Handler b e a
+ -> [(Text, SnapletSplice b v)]
+ -> Handler b v a
+ -> Handler b v a
withSplices heist splices m = withSplices' (subSnaplet heist) splices m
renderWithSplices' :: (Snaplet b :-> Snaplet (Heist b))
-> ByteString
- -> [(Text, SnapletSplice b e)]
- -> Handler b e ()
+ -> [(Text, SnapletSplice b v)]
+ -> Handler b v ()
renderWithSplices' heist t splices =
withSplices' heist splices $ withTop' heist $ render t
renderWithSplices :: (b :-> Snaplet (Heist b))
-> ByteString
- -> [(Text, SnapletSplice b e)]
- -> Handler b e ()
+ -> [(Text, SnapletSplice b v)]
+ -> Handler b v ()
renderWithSplices heist t splices =
renderWithSplices' (subSnaplet heist) t splices
Oops, something went wrong.

0 comments on commit b8a1e4f

Please sign in to comment.