projects
/
ghc-base.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
b56d2e6
)
add Applicative instance for Either (proposal #4095)
author
Ross Paterson
<ross@soi.city.ac.uk>
Thu, 17 Jun 2010 22:51:10 +0000
(22:51 +0000)
committer
Ross Paterson
<ross@soi.city.ac.uk>
Thu, 17 Jun 2010 22:51:10 +0000
(22:51 +0000)
This is not the only possible instance for Either, but this one is
compatible with the usual Monad instance.
Control/Applicative.hs
patch
|
blob
|
history
diff --git
a/Control/Applicative.hs
b/Control/Applicative.hs
index
a2755eb
..
154b591
100644
(file)
--- a/
Control/Applicative.hs
+++ b/
Control/Applicative.hs
@@
-167,6
+167,11
@@
instance Monoid a => Applicative ((,) a) where
pure x = (mempty, x)
(u, f) <*> (v, x) = (u `mappend` v, f x)
+instance Applicative (Either e) where
+ pure = Right
+ Left e <*> _ = Left e
+ Right f <*> r = fmap f r
+
-- new instances
newtype Const a b = Const { getConst :: a }