@@ -16,7 +16,7 @@ module Text.Libyaml
16 , YamlException (..)
16 , YamlException (..)
17 -- * Enumerator
17 -- * Enumerator
18 , EnumResult (..)
18 , EnumResult (..)
19− , RMonadIO (..)
19+ , With (..)
20 -- * Encoder
20 -- * Encoder
21 , YamlEncoder
21 , YamlEncoder
22 , YamlDecoder
22 , YamlDecoder
@@ -167,19 +167,19 @@ foreign import ccall unsafe "fclose"
167 c_fclose :: File
167 c_fclose :: File
170−class MonadIO m => RMonadIO m where
170+class MonadIO m => With m where
171− withR :: ((a -> IO b) -> IO b) -> (a -> m b) -> m b
171+ with :: ((a -> IO b) -> IO b) -> (a -> m b) -> m b
173−instance RMonadIO IO where
173+instance With IO where
174− withR = id
174+ with = id
176−allocaBytesR :: RMonadIO m => Int -> (Ptr a -> m b) -> m b
176+allocaBytesR :: With m => Int -> (Ptr a -> m b) -> m b
177−allocaBytesR = withR . allocaBytes
177+allocaBytesR = with . allocaBytes
179−withCStringR :: RMonadIO m => String -> (Ptr CChar -> m a) -> m a
179+withCStringR :: With m => String -> (Ptr CChar -> m a) -> m a
180−withCStringR = withR . withCString
180+withCStringR = with . withCString
182−withFileParser :: (MonadFailure YamlException m, RMonadIO m)
182+withFileParser :: (MonadFailure YamlException m, With m)
183 => FilePath
183 => FilePath
184 -> (Parser -> m a)
184 -> (Parser -> m a)
@@ -195,7 +195,7 @@ withFileParser fp f = allocaBytesR parserSize $ \p -> do
195 liftIO $ c_yaml_parser_delete p -- could use some finallys here
195 liftIO $ c_yaml_parser_delete p -- could use some finallys here
196 return ret
196 return ret
198−withParser :: (MonadFailure YamlException m, RMonadIO m)
198+withParser :: (MonadFailure YamlException m, With m)
199 => B.ByteString
199 => B.ByteString
200 -> (Parser -> m a)
200 -> (Parser -> m a)
@@ -211,8 +211,8 @@ withParser bs f = allocaBytesR parserSize $ \p -> do
211 liftIO $ c_yaml_parser_delete p -- FIXME use finally
211 liftIO $ c_yaml_parser_delete p -- FIXME use finally
212 return ret
212 return ret
214−withForeignPtrR :: RMonadIO m => ForeignPtr a -> (Ptr a -> m b) -> m b
214+withForeignPtrR :: With m => ForeignPtr a -> (Ptr a -> m b) -> m b
215−withForeignPtrR = withR . withForeignPtr
215+withForeignPtrR = with . withForeignPtr
217foreign import ccall unsafe "yaml_parser_parse"
217foreign import ccall unsafe "yaml_parser_parse"
218 c_yaml_parser_parse :: Parser -> EventRaw -> IO CInt
218 c_yaml_parser_parse :: Parser -> EventRaw -> IO CInt
@@ -234,7 +234,7 @@ makeString f a = do
234 cchar <- castPtr `liftM` f a
234 cchar <- castPtr `liftM` f a
235 liftIO $ peekCString cchar
235 liftIO $ peekCString cchar
237−parserParseOne :: (MonadFailure YamlException m, RMonadIO m)
237+parserParseOne :: (MonadFailure YamlException m, With m)
238 => Parser
238 => Parser
239 -> m Event
239 -> m Event
240parserParseOne parser = allocaBytesR eventSize $ \er -> do
240parserParseOne parser = allocaBytesR eventSize $ \er -> do
@@ -316,7 +316,7 @@ getEvent er = do
316 YamlMappingStartEvent -> return EventMappingStart
316 YamlMappingStartEvent -> return EventMappingStart
317 YamlMappingEndEvent -> return EventMappingEnd
317 YamlMappingEndEvent -> return EventMappingEnd
319−parserParse :: (MonadFailure YamlException m, RMonadIO m)
319+parserParse :: (MonadFailure YamlException m, With m)
320 => (a -> Event -> m (EnumResult a b))
320 => (a -> Event -> m (EnumResult a b))
322 -> Parser
322 -> Parser
@@ -355,7 +355,7 @@ foreign import ccall unsafe "get_buffer_buff"
355foreign import ccall unsafe "get_buffer_used"
355foreign import ccall unsafe "get_buffer_used"
356 c_get_buffer_used :: Buffer -> IO CULong
356 c_get_buffer_used :: Buffer -> IO CULong
358−withBufferR :: (RMonadIO m, MonadFailure YamlException m)
358+withBufferR :: (With m, MonadFailure YamlException m)
359 => (Buffer -> m ())
359 => (Buffer -> m ())
360 -> m B.ByteString
360 -> m B.ByteString
361withBufferR f = allocaBytesR bufferSize $ \b -> do
361withBufferR f = allocaBytesR bufferSize $ \b -> do
@@ -369,7 +369,7 @@ withBufferR f = allocaBytesR bufferSize $ \b -> do
369foreign import ccall unsafe "my_emitter_set_output"
369foreign import ccall unsafe "my_emitter_set_output"
370 c_my_emitter_set_output :: Emitter -> Buffer -> IO ()
370 c_my_emitter_set_output :: Emitter -> Buffer -> IO ()
372−withEmitter :: (RMonadIO m, MonadFailure YamlException m)
372+withEmitter :: (With m, MonadFailure YamlException m)
373 => (Emitter -> m ())
373 => (Emitter -> m ())
374 -> m B.ByteString
374 -> m B.ByteString
375withEmitter f = allocaBytesR emitterSize $ \e -> do
375withEmitter f = allocaBytesR emitterSize $ \e -> do
@@ -384,7 +384,7 @@ withEmitter f = allocaBytesR emitterSize $ \e -> do
384foreign import ccall unsafe "yaml_emitter_set_output_file"
384foreign import ccall unsafe "yaml_emitter_set_output_file"
385 c_yaml_emitter_set_output_file :: Emitter -> File -> IO ()
385 c_yaml_emitter_set_output_file :: Emitter -> File -> IO ()
387−withEmitterFile :: (RMonadIO m, MonadFailure YamlException m)
387+withEmitterFile :: (With m, MonadFailure YamlException m)
388 => FilePath
388 => FilePath
389 -> (Emitter -> m ())
389 -> (Emitter -> m ())
@@ -420,17 +420,17 @@ emitEvent e = do
420 problem <- liftIO $ makeString c_get_emitter_error emitter
420 problem <- liftIO $ makeString c_get_emitter_error emitter
421 failure $ YamlEmitterException e problem
421 failure $ YamlEmitterException e problem
423−parseEvent :: (RMonadIO m, MonadFailure YamlException m)
423+parseEvent :: (With m, MonadFailure YamlException m)
424 => YamlDecoder m Event
424 => YamlDecoder m Event
425parseEvent = ask >>= parserParseOne
425parseEvent = ask >>= parserParseOne
427type YamlDecoder = ReaderT Parser
427type YamlDecoder = ReaderT Parser
428type YamlEncoder = ReaderT Emitter
428type YamlEncoder = ReaderT Emitter
430−instance RMonadIO m => RMonadIO (ReaderT r m) where
430+instance With m => With (ReaderT r m) where
431− withR orig f = ReaderT $ \r -> do
431+ with orig f = ReaderT $ \r -> do
432 let f' a = (runReaderT $ f a) r
432 let f' a = (runReaderT $ f a) r
433− withR orig f'
433+ with orig f'
434instance MonadFailure e m => Failure e (ReaderT r m) where
434instance MonadFailure e m => Failure e (ReaderT r m) where
435 failure = lift . failure
435 failure = lift . failure
@@ -547,32 +547,32 @@ instance Exception ToEventRawException
547data EnumResult a b = More a | Done b
547data EnumResult a b = More a | Done b
548 deriving (Eq, Show)
548 deriving (Eq, Show)
550−encode :: (RMonadIO m, MonadFailure YamlException m)
550+encode :: (With m, MonadFailure YamlException m)
551 => YamlEncoder m ()
551 => YamlEncoder m ()
552 -> m B.ByteString
552 -> m B.ByteString
553encode = withEmitter . runReaderT
553encode = withEmitter . runReaderT
555−encodeFile :: (RMonadIO m, MonadFailure YamlException m)
555+encodeFile :: (With m, MonadFailure YamlException m)
556 => FilePath
556 => FilePath
557 -> YamlEncoder m ()
557 -> YamlEncoder m ()
559encodeFile filePath = withEmitterFile filePath . runReaderT
559encodeFile filePath = withEmitterFile filePath . runReaderT
561−decode :: (RMonadIO m, MonadFailure YamlException m)
561+decode :: (With m, MonadFailure YamlException m)
562 => B.ByteString
562 => B.ByteString
563 -> (a -> Event -> m (EnumResult a b))
563 -> (a -> Event -> m (EnumResult a b))
566decode bs fold accum = withParser bs $ parserParse fold accum
566decode bs fold accum = withParser bs $ parserParse fold accum
568−decodeFile :: (RMonadIO m, MonadFailure YamlException m)
568+decodeFile :: (With m, MonadFailure YamlException m)
569 => FilePath
569 => FilePath
570 -> (a -> Event -> m (EnumResult a b))
570 -> (a -> Event -> m (EnumResult a b))
573decodeFile fp fold accum = withFileParser fp $ parserParse fold accum
573decodeFile fp fold accum = withFileParser fp $ parserParse fold accum
575−decodeFile' :: (RMonadIO m, MonadFailure YamlException m)
575+decodeFile' :: (With m, MonadFailure YamlException m)
576 => FilePath
576 => FilePath
577 -> YamlDecoder m a
577 -> YamlDecoder m a