packages feed

acme-strtok 0.1.0.2 → 0.1.0.3

raw patch · 2 files changed

+7/−35 lines, 2 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Acme.StrTok: instance (Functor m, Monad m) => Applicative (StrTokT s m)
+ Acme.StrTok: instance (Monad m, Functor m) => Applicative (StrTokT s m)

Files

Acme/StrTok.hs view
@@ -10,6 +10,7 @@ @strTok@ is a stateful function (it produces different results when called with the same parameter multiple times),  computations using @strTok@ must take place in the @StrTok@ monad or the @StrTokT@ monad transformer. -}+{-# LANGUAGE GeneralizedNewtypeDeriving #-} module Acme.StrTok (     -- * The StrTokT monad transformer     StrTokT,@@ -23,8 +24,8 @@  import Control.Applicative import Control.Monad+import Control.Monad.State import Control.Monad.Identity-import Control.Arrow import Control.Monad.Trans  @@ -33,41 +34,12 @@ --   * @s@ - The type of list elements (e.g. @Char@ if the input to @strTok@ is a @String@). -- --   * @m@ - The inner monad.-newtype StrTokT s m a = StrTokT { runStrTokT' :: [s] -> m (a, [s]) }--instance Functor m => Functor (StrTokT s m) where-  fmap f (StrTokT g) = StrTokT $ fmap (first f) . g-  -instance (Functor m, Monad m) => Applicative (StrTokT s m) where-  pure  = return-  (<*>) = ap-  -instance (Functor m, MonadPlus m) => Alternative (StrTokT s m) where-  empty = mzero-  (<|>) = mplus-    -instance (MonadPlus m) => MonadPlus (StrTokT s m) where-  mzero       = StrTokT $ const mzero-  m `mplus` n = StrTokT $ \s -> runStrTokT' m s `mplus` runStrTokT' n s--instance (MonadFix m) => MonadFix (StrTokT s m) where-  mfix f = StrTokT $ \s -> mfix $ \ ~(a, _) -> runStrTokT' (f a) s   --instance Monad m => Monad (StrTokT s m) where-  return x = StrTokT $ \s -> return (x,s)-  StrTokT f >>= g = StrTokT $ \s -> do {(x,s) <- f s; runStrTokT' (g x) s}--instance MonadTrans (StrTokT s) where-  lift m = StrTokT $ \s -> do {x <- m; return (x,s)}-  -instance (MonadIO m) => MonadIO (StrTokT s m) where-    liftIO = lift . liftIO+newtype StrTokT s m a = StrTokT (StateT [s] m a) +  deriving (Functor, Applicative, Alternative, Monad, MonadPlus, MonadFix, MonadTrans, MonadIO)  -- | Executes a @strTok@ computation in the state transformer monad @StrTokT@. runStrTokT :: Functor m => StrTokT s m a -> m a-runStrTokT (StrTokT f) = fmap fst (f [])--+runStrTokT (StrTokT x) = fmap fst (runStateT x [])  -- | The @StrTok@ monad. type StrTok s = StrTokT s Identity@@ -99,7 +71,7 @@ -- -- >("This","a"," sample string") strTok :: (Eq a, Monad m) => Maybe [a] -> [a] -> StrTokT a m [a]-strTok s delims = StrTokT $ maybe strTok' (const . strTok') s+strTok s delims = StrTokT $ StateT $ maybe strTok' (const . strTok') s   where strTok' = return . break (`elem` delims) . dropWhile (`elem` delims)  
acme-strtok.cabal view
@@ -10,7 +10,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.1.0.2+version:             0.1.0.3  -- A short (one-line) description of the package. synopsis:            A Haskell port of the C/PHP strtok function