@@ -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