From 576aee6c99f9d06a4faa44f4cef17b68672f07d0 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Mon, 14 Aug 2017 20:45:14 -0400 Subject: [PATCH] gray: AMP compatibility Reviewers: O26 nofib, michalt Reviewed By: O26 nofib, michalt Subscribers: michalt Differential Revision: https://phabricator.haskell.org/D3730 --- 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 -- GitLab