switch to Except type of transformers-compat.

This commit is contained in:
Kei Hibino 2017-01-05 12:24:39 +09:00
parent 599b247ebc
commit 554211d933
2 changed files with 7 additions and 7 deletions

View File

@ -8,27 +8,26 @@ module Text.Parser.List
import Control.Applicative (pure) import Control.Applicative (pure)
import Control.Monad (guard) import Control.Monad (guard)
import Control.Monad.Trans.State.Strict (StateT (..), evalStateT, get, put) import Control.Monad.Trans.State.Strict (StateT (..), evalStateT, get, put)
import Control.Monad.Trans.Except (Except, runExcept, withExcept, throwE)
import Data.Monoid (Last (..)) import Data.Monoid (Last (..))
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import Control.Monad.Either.Plus (EitherP (..), emap, leftP)
type Error = Last String type Error = Last String
unError :: String -> Error -> String unError :: String -> Error -> String
unError s = fromMaybe s . getLast unError s = fromMaybe s . getLast
type Parser t = StateT [t] (EitherP Error) type Parser t = StateT [t] (Except Error)
runParser :: Parser t a -> [t] -> Either String (a, [t]) runParser :: Parser t a -> [t] -> Either String (a, [t])
runParser p = unEitherP . emap (unError "runParser: parse error.") . runStateT p runParser p = runExcept . withExcept (unError "runParser: parse error.") . runStateT p
evalParser :: Parser t a -> [t] -> Either String a evalParser :: Parser t a -> [t] -> Either String a
evalParser p = unEitherP . emap (unError "evalParser: parse error.") . evalStateT p evalParser p = runExcept . withExcept (unError "evalParser: parse error.") . evalStateT p
errorE :: String -> EitherP Error a errorE :: String -> Except Error a
errorE = leftP . Last . Just errorE = throwE . Last . Just
errorP :: String -> Parser t a errorP :: String -> Parser t a
errorP = StateT . const . errorE errorP = StateT . const . errorE

View File

@ -32,6 +32,7 @@ library
build-depends: base <5 build-depends: base <5
, transformers , transformers
, transformers-compat
, dlist , dlist
hs-source-dirs: src hs-source-dirs: src
default-language: Haskell2010 default-language: Haskell2010