packages feed

formlets 0.4 → 0.4.1

raw patch · 2 files changed

+12/−9 lines, 2 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Text.Formlets: pureM :: (Monad m, Plus xml) => m a -> Form xml m a
- Text.Formlets: plug :: (Plus xml) => (xml -> xml) -> Form xml m a -> Form xml m a
+ Text.Formlets: plug :: (Plus xml) => (xml -> xml1) -> Form xml m a -> Form xml1 m a

Files

Text/Formlets.hs view
@@ -1,5 +1,6 @@ module Text.Formlets ( input', inputFile, fmapFst-                     , check, ensure, ensures, ensureM, checkM+                     , check, ensure, ensures+                     , ensureM, checkM, pureM                      , runFormState                       , xml, plug                      , Env , Form , Plus (..)@@ -16,8 +17,7 @@  -- Form stuff type Env = [(String, Either String File)]-type FormState = Names-type Names = Integer+type FormState = (Integer, String) type Name = String type Collector a = Env -> a data FormContentType = UrlEncoded | MultiPart deriving (Eq, Show, Read)@@ -81,10 +81,10 @@  -- | Runs the form state runFormState :: Monad m -             => Env             -- ^ A previously filled environment (may be empty)+             => Env               -- ^ A previously filled environment (may be empty)              -> Form xml m a      -- ^ The form              -> (Collector (m (Failing a)), xml, FormContentType)-runFormState e (Form f) = evalState (f e) 0+runFormState e (Form f) = evalState (f e) (0, "")  -- | Add additional validation to an already validated component check :: (Monad m) => Form xml m a -> (a -> Failing b) -> Form xml m b@@ -115,6 +115,9 @@ pureF :: (Monad m, Plus xml) => a -> Form xml m a pureF v = Form $ \env -> pure (const (return $ Success v), zero, UrlEncoded) +pureM :: (Monad m, Plus xml) => m a -> Form xml m a+pureM v = Form $ \env -> pure (const (liftM Success v), zero, UrlEncoded)+ applyF :: (Monad m, Applicative m, Plus xml) => Form xml m (a -> b) -> Form xml m a -> Form xml m b (Form f) `applyF` (Form v) = Form $ \env -> pure combine <*> f env <*> v env   where combine (v1, xml1, t1) (v2, xml2, t2) = (first v1 v2, xml1 `plus` xml2, t1 `orT` t2)@@ -132,7 +135,7 @@ xml x = Form $ \env -> pure (const $ return $ Success (), x, UrlEncoded)  -- | Transform the XML component-plug :: Plus xml => (xml -> xml) -> Form xml m a -> Form xml m a+plug :: Plus xml => (xml -> xml1) -> Form xml m a -> Form xml1 m a f `plug` (Form m) = Form $ \env -> pure plugin <*> m env    where plugin (c, x, t) = (c, f x, t) @@ -142,8 +145,8 @@  freshName :: State FormState String freshName = do n <- currentName-               modify (+1)+               modify (\(n,prefix) -> (n+1, prefix))                return n  currentName :: State FormState String-currentName = gets $ (++) "input" . show+currentName = gets $ \(n, prefix) ->  prefix ++ "input" ++ show n
formlets.cabal view
@@ -1,5 +1,5 @@ Name:            formlets-Version:         0.4+Version:         0.4.1 Synopsis:        Formlets implemented in Haskell Description:     A modular way to build forms based on applicative functors, as                  described in: