[commit: packages/containers] ghc-head: Applicative and Alternative instances for Seq (14a65a2)

git at git.haskell.org git at git.haskell.org
Fri Aug 30 13:34:29 CEST 2013


Repository : ssh://git@git.haskell.org/containers

On branch  : ghc-head
Link       : http://git.haskell.org/?p=packages/containers.git;a=commit;h=14a65a2e403fac166653665a2df071d46e96601e

>---------------------------------------------------------------

commit 14a65a2e403fac166653665a2df071d46e96601e
Author: Taneb <nvd1234 at gmail.com>
Date:   Wed Nov 14 12:10:54 2012 +0000

    Applicative and Alternative instances for Seq
    
    The Alternative instance is basically the same as the pre-existing
    MonadPlus instance, except names are qualified (empty clashes with
    empty). The Applicative instance is similar to the Monad instance, and
    relies on ap.


>---------------------------------------------------------------

14a65a2e403fac166653665a2df071d46e96601e
 Data/Sequence.hs |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/Data/Sequence.hs b/Data/Sequence.hs
index c6263d5..bd60ea4 100644
--- a/Data/Sequence.hs
+++ b/Data/Sequence.hs
@@ -142,7 +142,9 @@ import Prelude hiding (
     scanl, scanl1, scanr, scanr1, replicate, zip, zipWith, zip3, zipWith3,
     takeWhile, dropWhile, iterate, reverse, filter, mapM, sum, all)
 import qualified Data.List
-import Control.Applicative (Applicative(..), (<$>), WrappedMonad(..), liftA, liftA2, liftA3)
+import Control.Applicative (Applicative(..), (<$>), WrappedMonad(..), liftA,
+                            liftA2, liftA3)
+import qualified Control.Applicative as Applicative
 import Control.DeepSeq (NFData(rnf))
 import Control.Monad (MonadPlus(..), ap)
 import Data.Monoid (Monoid(..))
@@ -198,10 +200,18 @@ instance Monad Seq where
     xs >>= f = foldl' add empty xs
       where add ys x = ys >< f x
 
+instance Applicative Seq where
+    pure = singleton
+    (<*>) = ap
+
 instance MonadPlus Seq where
     mzero = empty
     mplus = (><)
 
+instance Applicative.Alternative Seq where
+    empty = empty
+    (<|>) = (><)
+
 instance Eq a => Eq (Seq a) where
     xs == ys = length xs == length ys && toList xs == toList ys
 





More information about the ghc-commits mailing list