on master help sign in
Rename RMonadIO to With
commit489230247ab26616662e657c6f82ab132d0664b4 authorMichael Snoyman <michael@snoyman.com> dateThu 14 Jan 2010, 00:48 (17 years ago) parentbca93d6
1 file changed+27−27
Text/Libyaml.hs+27−27
Text/Libyaml.hs+27−27
@@ -16,7 +16,7 @@ module Text.Libyaml
1616 , YamlException (..)
1717 -- * Enumerator
1818 , EnumResult (..)
19− , RMonadIO (..)
19+ , With (..)
2020 -- * Encoder
2121 , YamlEncoder
2222 , YamlDecoder
@@ -167,19 +167,19 @@ foreign import ccall unsafe "fclose"
167167 c_fclose :: File
168168 -> IO ()
169169
170−class MonadIO m => RMonadIO m where
171− withR :: ((a -> IO b) -> IO b) -> (a -> m b) -> m b
170+class MonadIO m => With m where
171+ with :: ((a -> IO b) -> IO b) -> (a -> m b) -> m b
172172
173−instance RMonadIO IO where
174− withR = id
173+instance With IO where
174+ with = id
175175
176−allocaBytesR :: RMonadIO m => Int -> (Ptr a -> m b) -> m b
177−allocaBytesR = withR . allocaBytes
176+allocaBytesR :: With m => Int -> (Ptr a -> m b) -> m b
177+allocaBytesR = with . allocaBytes
178178
179−withCStringR :: RMonadIO m => String -> (Ptr CChar -> m a) -> m a
180−withCStringR = withR . withCString
179+withCStringR :: With m => String -> (Ptr CChar -> m a) -> m a
180+withCStringR = with . withCString
181181
182−withFileParser :: (MonadFailure YamlException m, RMonadIO m)
182+withFileParser :: (MonadFailure YamlException m, With m)
183183 => FilePath
184184 -> (Parser -> m a)
185185 -> m a
@@ -195,7 +195,7 @@ withFileParser fp f = allocaBytesR parserSize $ \p -> do
195195 liftIO $ c_yaml_parser_delete p -- could use some finallys here
196196 return ret
197197
198−withParser :: (MonadFailure YamlException m, RMonadIO m)
198+withParser :: (MonadFailure YamlException m, With m)
199199 => B.ByteString
200200 -> (Parser -> m a)
201201 -> m a
@@ -211,8 +211,8 @@ withParser bs f = allocaBytesR parserSize $ \p -> do
211211 liftIO $ c_yaml_parser_delete p -- FIXME use finally
212212 return ret
213213
214−withForeignPtrR :: RMonadIO m => ForeignPtr a -> (Ptr a -> m b) -> m b
215−withForeignPtrR = withR . withForeignPtr
214+withForeignPtrR :: With m => ForeignPtr a -> (Ptr a -> m b) -> m b
215+withForeignPtrR = with . withForeignPtr
216216
217217foreign import ccall unsafe "yaml_parser_parse"
218218 c_yaml_parser_parse :: Parser -> EventRaw -> IO CInt
@@ -234,7 +234,7 @@ makeString f a = do
234234 cchar <- castPtr `liftM` f a
235235 liftIO $ peekCString cchar
236236
237−parserParseOne :: (MonadFailure YamlException m, RMonadIO m)
237+parserParseOne :: (MonadFailure YamlException m, With m)
238238 => Parser
239239 -> m Event
240240parserParseOne parser = allocaBytesR eventSize $ \er -> do
@@ -316,7 +316,7 @@ getEvent er = do
316316 YamlMappingStartEvent -> return EventMappingStart
317317 YamlMappingEndEvent -> return EventMappingEnd
318318
319−parserParse :: (MonadFailure YamlException m, RMonadIO m)
319+parserParse :: (MonadFailure YamlException m, With m)
320320 => (a -> Event -> m (EnumResult a b))
321321 -> a
322322 -> Parser
@@ -355,7 +355,7 @@ foreign import ccall unsafe "get_buffer_buff"
355355foreign import ccall unsafe "get_buffer_used"
356356 c_get_buffer_used :: Buffer -> IO CULong
357357
358−withBufferR :: (RMonadIO m, MonadFailure YamlException m)
358+withBufferR :: (With m, MonadFailure YamlException m)
359359 => (Buffer -> m ())
360360 -> m B.ByteString
361361withBufferR f = allocaBytesR bufferSize $ \b -> do
@@ -369,7 +369,7 @@ withBufferR f = allocaBytesR bufferSize $ \b -> do
369369foreign import ccall unsafe "my_emitter_set_output"
370370 c_my_emitter_set_output :: Emitter -> Buffer -> IO ()
371371
372−withEmitter :: (RMonadIO m, MonadFailure YamlException m)
372+withEmitter :: (With m, MonadFailure YamlException m)
373373 => (Emitter -> m ())
374374 -> m B.ByteString
375375withEmitter f = allocaBytesR emitterSize $ \e -> do
@@ -384,7 +384,7 @@ withEmitter f = allocaBytesR emitterSize $ \e -> do
384384foreign import ccall unsafe "yaml_emitter_set_output_file"
385385 c_yaml_emitter_set_output_file :: Emitter -> File -> IO ()
386386
387−withEmitterFile :: (RMonadIO m, MonadFailure YamlException m)
387+withEmitterFile :: (With m, MonadFailure YamlException m)
388388 => FilePath
389389 -> (Emitter -> m ())
390390 -> m ()
@@ -420,17 +420,17 @@ emitEvent e = do
420420 problem <- liftIO $ makeString c_get_emitter_error emitter
421421 failure $ YamlEmitterException e problem
422422
423−parseEvent :: (RMonadIO m, MonadFailure YamlException m)
423+parseEvent :: (With m, MonadFailure YamlException m)
424424 => YamlDecoder m Event
425425parseEvent = ask >>= parserParseOne
426426
427427type YamlDecoder = ReaderT Parser
428428type YamlEncoder = ReaderT Emitter
429429
430−instance RMonadIO m => RMonadIO (ReaderT r m) where
431− withR orig f = ReaderT $ \r -> do
430+instance With m => With (ReaderT r m) where
431+ with orig f = ReaderT $ \r -> do
432432 let f' a = (runReaderT $ f a) r
433− withR orig f'
433+ with orig f'
434434instance MonadFailure e m => Failure e (ReaderT r m) where
435435 failure = lift . failure
436436
@@ -547,32 +547,32 @@ instance Exception ToEventRawException
547547data EnumResult a b = More a | Done b
548548 deriving (Eq, Show)
549549
550−encode :: (RMonadIO m, MonadFailure YamlException m)
550+encode :: (With m, MonadFailure YamlException m)
551551 => YamlEncoder m ()
552552 -> m B.ByteString
553553encode = withEmitter . runReaderT
554554
555−encodeFile :: (RMonadIO m, MonadFailure YamlException m)
555+encodeFile :: (With m, MonadFailure YamlException m)
556556 => FilePath
557557 -> YamlEncoder m ()
558558 -> m ()
559559encodeFile filePath = withEmitterFile filePath . runReaderT
560560
561−decode :: (RMonadIO m, MonadFailure YamlException m)
561+decode :: (With m, MonadFailure YamlException m)
562562 => B.ByteString
563563 -> (a -> Event -> m (EnumResult a b))
564564 -> a
565565 -> m b
566566decode bs fold accum = withParser bs $ parserParse fold accum
567567
568−decodeFile :: (RMonadIO m, MonadFailure YamlException m)
568+decodeFile :: (With m, MonadFailure YamlException m)
569569 => FilePath
570570 -> (a -> Event -> m (EnumResult a b))
571571 -> a
572572 -> m b
573573decodeFile fp fold accum = withFileParser fp $ parserParse fold accum
574574
575−decodeFile' :: (RMonadIO m, MonadFailure YamlException m)
575+decodeFile' :: (With m, MonadFailure YamlException m)
576576 => FilePath
577577 -> YamlDecoder m a
578578 -> m a