From e5e64a794f4309a124e422c8fd15f1fdaa11a218 Mon Sep 17 00:00:00 2001 From: "ryan.trinkle" Date: Fri, 16 Jan 2015 13:14:46 -0800 Subject: [PATCH] Add Applicative instances for instances of Monad Ignore-this: a95ef4a320b4c1506f5352716a656385 darcs-hash:20150116211446-5ff09-fca82019a01b124f7c93efe6f25ff73d1abfa665 --- Data/Encoding/ByteSink.hs | 28 ++++++++++++++++++++++++++++ encoding.cabal | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Data/Encoding/ByteSink.hs b/Data/Encoding/ByteSink.hs index 6432489..f403db0 100644 --- a/Data/Encoding/ByteSink.hs +++ b/Data/Encoding/ByteSink.hs @@ -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 diff --git a/encoding.cabal b/encoding.cabal index fa49e3b..1c8287a 100644 --- a/encoding.cabal +++ b/encoding.cabal @@ -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