From c4e2f1ff52f592acedd9de932ad7b8164d717889 Mon Sep 17 00:00:00 2001 From: Yoshikuni Jujo Date: Wed, 21 Jan 2015 09:16:34 +0900 Subject: [PATCH] add Alternative and Applicative to Parse and ParseT --- Text/ParserCombinators/MTLParse/MTLParseCore.hs | 13 ++++++++++++- mtlparse.cabal | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Text/ParserCombinators/MTLParse/MTLParseCore.hs b/Text/ParserCombinators/MTLParse/MTLParseCore.hs index 55a0c4b..e19259d 100644 --- a/Text/ParserCombinators/MTLParse/MTLParseCore.hs +++ b/Text/ParserCombinators/MTLParse/MTLParseCore.hs @@ -65,7 +65,7 @@ module Text.ParserCombinators.MTLParse.MTLParseCore ( ) where -import Control.Applicative ( Applicative(..) ) +import Control.Applicative ( Applicative(..), Alternative(..) ) import Control.Monad ( MonadPlus, mplus, mzero, liftM, ap ) import Control.Monad.Trans ( MonadTrans( lift ), MonadIO, liftIO ) @@ -127,6 +127,10 @@ instance Functor ( Parse p ) where instance Applicative ( Parse p ) where pure = return; (<*>) = ap +instance Alternative (Parse p ) where + empty = mzero + (<|>) = mplus + instance Monad ( Parse a ) where return = Parse . \val inp -> [ (val, inp) ] Parse pr >>= f @@ -190,6 +194,13 @@ instance Monad m => Functor ( ParseT a m ) where rets <- runParseT m a return [ ( f a', rst ) | ( a', rst ) <- rets ] +instance Monad m => Applicative ( ParseT a m ) where + pure = return; (<*>) = ap + +instance Monad m => Alternative (ParseT a m ) where + empty = mzero + (<|>) = mplus + instance Monad m => Monad ( ParseT a m ) where return b = ParseT $ \a -> return [ (b, a) ] ParseT pr >>= f diff --git a/mtlparse.cabal b/mtlparse.cabal index 6d85028..9ae2511 100644 --- a/mtlparse.cabal +++ b/mtlparse.cabal @@ -1,5 +1,5 @@ Name: mtlparse -Version: 0.1.3.0 +Version: 0.1.4.0 License: LGPL License-File: LICENSE Author: Yoshikuni Jujo -- 2.11.4.GIT