Add Applicative instances for instances of Monad

Ignore-this: a95ef4a320b4c1506f5352716a656385

darcs-hash:20150116211446-5ff09-fca82019a01b124f7c93efe6f25ff73d1abfa665
This commit is contained in:
ryan.trinkle 2015-01-16 13:14:46 -08:00
parent f679a9eb63
commit e5e64a794f
2 changed files with 29 additions and 1 deletions

View File

@ -80,6 +80,13 @@ instance ByteSink PutM where
newtype PutME a = PutME (Either EncodingException (PutM (),a))
instance Functor PutME where
fmap = liftM
instance Applicative PutME where
pure = return
(<*>) = ap
instance Monad PutME where
return x = PutME $ Right (return (),x)
(PutME x) >>= g = PutME $ do
@ -114,6 +121,13 @@ instance (Monad m,Throws EncodingException m) => ByteSink (StateT (Seq Char) m)
newtype StrictSink a = StrictS (Ptr Word8 -> Int -> Int -> IO (a,Ptr Word8,Int,Int))
instance Functor StrictSink where
fmap = liftM
instance Applicative StrictSink where
pure = return
(<*>) = ap
instance Monad StrictSink where
return x = StrictS $ \cstr pos max -> return (x,cstr,pos,max)
(StrictS f) >>= g = StrictS (\cstr pos max -> do
@ -140,6 +154,13 @@ instance ByteSink StrictSink where
newtype StrictSinkE a = StrictSinkE (StrictSink (Either EncodingException a))
instance Functor StrictSinkE where
fmap = liftM
instance Applicative StrictSinkE where
pure = return
(<*>) = ap
instance Monad StrictSinkE where
return = StrictSinkE . return . Right
(StrictSinkE s) >>= g = StrictSinkE $ do
@ -167,6 +188,13 @@ createStrict sink = createStrictWithLen sink 32
newtype StrictSinkExplicit a = StrictSinkExplicit (StrictSink (Either EncodingException a))
instance Functor StrictSinkExplicit where
fmap = liftM
instance Applicative StrictSinkExplicit where
pure = return
(<*>) = ap
instance Monad StrictSinkExplicit where
return = (StrictSinkExplicit).return.Right
(StrictSinkExplicit sink) >>= f

View File

@ -1,5 +1,5 @@
Name: encoding
Version: 0.7.0.2
Version: 0.7.0.3
Author: Henning Günther
Maintainer: daniel@wagner-home.com
License: BSD3