on master help sign in
Removed MyReaderT by moving to c-m-f
commit48b5ad55eab8a80abf067df60970ee8ec90184ef authorMichael Snoyman <michael@snoyman.com> dateTue 19 Jan 2010, 17:23 (17 years ago) parent3746497
2 files changed+14−21
Text/Libyaml.hs+12−19 yaml.cabal+2−2
Text/Libyaml.hs+12−19
@@ -39,10 +39,9 @@ import Foreign.Ptr
3939import Foreign.ForeignPtr
4040import Foreign.Marshal.Alloc
4141import "transformers" Control.Monad.Trans
42−import Control.Failure
42+import Control.Monad.Failure.Transformers
4343import qualified Control.Monad.Trans.Error as ErrorT
4444import Control.Monad.Trans.Reader
45−import Control.Applicative
4645
4746import Control.Exception (throwIO, Exception, SomeException)
4847import Data.Typeable (Typeable)
@@ -126,8 +125,11 @@ data YamlException =
126125 | YamlInvalidStartingEvent Event
127126 | YamlFileNotFound FilePath
128127 | YamlOtherException SomeException
128+ | YamlStringException String
129129 deriving (Show, Typeable)
130130instance Exception YamlException
131+instance ErrorT.Error YamlException where
132+ strMsg = YamlStringException
131133
132134data ParserStruct
133135type Parser = Ptr ParserStruct
@@ -409,7 +411,7 @@ emitEvent :: (MonadIO m, MonadFailure YamlException m)
409411 => Event
410412 -> YamlEncoder m ()
411413emitEvent e = do
412− emitter <- MyReaderT ask
414+ emitter <- ask
413415 res <- liftIO $ toEventRaw e $ c_yaml_emitter_emit emitter
414416 when (res == 0) $ do
415417 problem <- liftIO $ makeString c_get_emitter_error emitter
@@ -417,19 +419,10 @@ emitEvent e = do
417419
418420parseEvent :: (With m, MonadFailure YamlException m)
419421 => YamlDecoder m Event
420−parseEvent = MyReaderT ask >>= parserParseOne
422+parseEvent = ask >>= parserParseOne
421423
422−runMyReaderT :: MyReaderT r m a -> r -> m a
423−runMyReaderT (MyReaderT (ReaderT f)) = f
424−
425−newtype MyReaderT r m a = MyReaderT (ReaderT r m a)
426− deriving (MonadTrans, MonadIO, Functor, Applicative,
427− Alternative, Monad, MonadPlus, With)
428−type YamlDecoder = MyReaderT Parser
429−type YamlEncoder = MyReaderT Emitter
430−
431−instance MonadFailure e m => Failure e (MyReaderT r m) where
432− failure = lift . failure
424+type YamlDecoder = ReaderT Parser
425+type YamlEncoder = ReaderT Emitter
433426
434427foreign import ccall unsafe "yaml_stream_start_event_initialize"
435428 c_yaml_stream_start_event_initialize :: EventRaw -> CInt -> IO CInt
@@ -544,22 +537,22 @@ instance Exception ToEventRawException
544537encode :: (With m, MonadFailure YamlException m)
545538 => YamlEncoder m ()
546539 -> m B.ByteString
547−encode = withEmitter . runMyReaderT
540+encode = withEmitter . runReaderT
548541
549542encodeFile :: (With m, MonadFailure YamlException m)
550543 => FilePath
551544 -> YamlEncoder m ()
552545 -> m ()
553−encodeFile filePath = withEmitterFile filePath . runMyReaderT
546+encodeFile filePath = withEmitterFile filePath . runReaderT
554547
555548decode :: (With m, MonadFailure YamlException m)
556549 => B.ByteString
557550 -> YamlDecoder m a
558551 -> m a
559−decode bs dec = withParser bs $ runMyReaderT dec
552+decode bs dec = withParser bs $ runReaderT dec
560553
561554decodeFile :: (With m, MonadFailure YamlException m)
562555 => FilePath
563556 -> YamlDecoder m a
564557 -> m a
565−decodeFile fp dec = withFileParser fp $ runMyReaderT dec
558+decodeFile fp dec = withFileParser fp $ runReaderT dec
yaml.cabal+2−2
@@ -29,7 +29,7 @@ library
2929 Buildable: True
3030 build-depends: base >= 4 && < 5,
3131 transformers >= 0.1 && < 0.2,
32− failure >= 0.0.0.1 && < 0.1,
32+ control-monad-failure >= 0.6.0 && < 0.7,
3333 bytestring >= 0.9.1.4 && < 0.10
3434 exposed-modules: Text.Libyaml
3535 ghc-options: -Wall -auto-all -caf-all
@@ -55,7 +55,7 @@ executable runtests
5555 QuickCheck >= 1 && < 2,
5656 base >= 4 && < 5,
5757 transformers >= 0.1 && < 0.2,
58− failure >= 0.0.0.1 && < 0.1,
58+ control-monad-failure >= 0.6.0 && < 0.7,
5959 bytestring >= 0.9.1.4 && < 0.10
6060 else
6161 Buildable: False