diff --git a/parallel/gray/Eval.hs b/parallel/gray/Eval.hs index 367942b616816faf7fb2b812539c9791e25a4b1b..29c2bac54c896141c0063686d77a0e86f31483cb 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