[commit: nofib] master: gray: AMP compatibility (576aee6)
git at git.haskell.org
git at git.haskell.org
Tue Aug 15 01:35:10 UTC 2017
Repository : ssh://git@git.haskell.org/nofib
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/576aee6c99f9d06a4faa44f4cef17b68672f07d0/nofib
>---------------------------------------------------------------
commit 576aee6c99f9d06a4faa44f4cef17b68672f07d0
Author: Ben Gamari <ben at smart-cactus.org>
Date: Mon Aug 14 20:45:14 2017 -0400
gray: AMP compatibility
Reviewers: O26 nofib, michalt
Reviewed By: O26 nofib, michalt
Subscribers: michalt
Differential Revision: https://phabricator.haskell.org/D3730
>---------------------------------------------------------------
576aee6c99f9d06a4faa44f4cef17b68672f07d0
parallel/gray/Eval.hs | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/parallel/gray/Eval.hs b/parallel/gray/Eval.hs
index 367942b..29c2bac 100644
--- a/parallel/gray/Eval.hs
+++ b/parallel/gray/Eval.hs
@@ -14,6 +14,7 @@ import Data
import Parse (rayParse, rayParseF)
import Control.Parallel
+import Control.Monad (ap)
class Monad m => MonadEval m where
doOp :: PrimOp -> GMLOp -> Stack -> m Stack
@@ -24,6 +25,13 @@ class Monad m => MonadEval m where
newtype Pure a = Pure a deriving Show
+instance Functor Pure where
+ fmap f (Pure x) = Pure (f x)
+
+instance Applicative Pure where
+ pure = Pure
+ Pure f <*> Pure x = Pure (f x)
+
instance Monad Pure where
Pure x >>= k = k x
return = Pure
@@ -293,11 +301,18 @@ newtype Abs a = Abs { runAbs :: Int -> AbsState a }
data AbsState a = AbsState a !Int
| AbsFail String
+instance Functor Abs where
+ fmap f = (pure f <*>)
+
+instance Applicative Abs where
+ pure x = Abs (\ n -> AbsState x n)
+ (<*>) = ap
+
instance Monad Abs where
(Abs fn) >>= k = Abs (\ s -> case fn s of
AbsState r s' -> runAbs (k r) s'
AbsFail m -> AbsFail m)
- return x = Abs (\ n -> AbsState x n)
+ return = pure
fail s = Abs (\ n -> AbsFail s)
instance MonadEval Abs where
More information about the ghc-commits
mailing list