@@ -18,6 +18,9 @@ module Data.Text.Internal.Read
1818 , perhaps
1919 ) where
2020
21+import Control.Applicative (Applicative(..))
22+import Control.Arrow (first)
23+import Control.Monad (ap)
2124import Data.Char (ord)
2225
2326type IReader t a = t -> Either String (a,t)
@@ -26,9 +29,16 @@ newtype IParser t a = P {
2629 runP :: IReader t a
2730 }
2831
32+instance Functor (IParser t) where
33+ fmap f m = P $ fmap (first f) . runP m
34+
35+instance Applicative (IParser t) where
36+ pure a = P $ \t -> Right (a,t)
37+ {-# INLINE pure #-}
38+ (<*>) = ap
39+
2940instance Monad (IParser t) where
30− return a = P $ \t -> Right (a,t)
31− {-# INLINE return #-}
41+ return = pure
3242 m >>= k = P $ \t -> case runP m t of
3343 Left err -> Left err
3444 Right (a,t') -> runP (k a) t'