From 2df600835fc95e9a9ce947cdbac202c553ad13da Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 30 Nov 2017 17:43:30 -0500 Subject: [PATCH] Move MonadGC into its own module. --- semantic-diff.cabal | 1 + src/Abstract/Eval.hs | 17 +---------------- src/Control/Monad/Effect/GC.hs | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 src/Control/Monad/Effect/GC.hs diff --git a/semantic-diff.cabal b/semantic-diff.cabal index 285d0d30b..22e556924 100644 --- a/semantic-diff.cabal +++ b/semantic-diff.cabal @@ -39,6 +39,7 @@ library , Control.Effect , Control.Monad.Effect.Env , Control.Monad.Effect.Fresh + , Control.Monad.Effect.GC -- General datatype definitions & generic algorithms , Data.Algebra , Data.Align.Generic diff --git a/src/Abstract/Eval.hs b/src/Abstract/Eval.hs index 19105071a..06fd64b8f 100644 --- a/src/Abstract/Eval.hs +++ b/src/Abstract/Eval.hs @@ -7,16 +7,12 @@ module Abstract.Eval import Abstract.Environment import Abstract.FreeVariables -import Abstract.Store import Abstract.Value -import Control.Monad.Effect import Control.Monad.Effect.Env -import Control.Monad.Effect.Reader +import Control.Monad.Effect.GC import Control.Monad.Fail import Data.Functor.Classes import Data.Proxy -import Data.Semigroup -import qualified Data.Set as Set import Data.Term import Data.Union import Prelude hiding (fail) @@ -35,17 +31,6 @@ instance (Monad m, Eval t v m s) => Eval t v m (TermF s a) where eval ev yield In{..} = eval ev yield termFOut -class Monad m => MonadGC a m where - askRoots :: m (Set.Set (Address (LocationFor a) a)) - - extraRoots :: Set.Set (Address (LocationFor a) a) -> m b -> m b - -instance (Ord (LocationFor a), Reader (Set.Set (Address (LocationFor a) a)) :< fs) => MonadGC a (Eff fs) where - askRoots = ask :: Eff fs (Set.Set (Address (LocationFor a) a)) - - extraRoots roots' = local (<> roots') - - instance ( Monad m , Ord (LocationFor v) , MonadGC v m diff --git a/src/Control/Monad/Effect/GC.hs b/src/Control/Monad/Effect/GC.hs new file mode 100644 index 000000000..31fd46b0a --- /dev/null +++ b/src/Control/Monad/Effect/GC.hs @@ -0,0 +1,19 @@ +{-# LANGUAGE MultiParamTypeClasses, ScopedTypeVariables, TypeOperators, UndecidableInstances #-} +module Control.Monad.Effect.GC where + +import Abstract.Address +import Abstract.Value +import Control.Monad.Effect +import Control.Monad.Effect.Reader +import Data.Semigroup ((<>)) +import Data.Set (Set) + +class Monad m => MonadGC a m where + askRoots :: m (Set (Address (LocationFor a) a)) + + extraRoots :: Set (Address (LocationFor a) a) -> m b -> m b + +instance (Ord (LocationFor a), Reader (Set (Address (LocationFor a) a)) :< fs) => MonadGC a (Eff fs) where + askRoots = ask :: Eff fs (Set (Address (LocationFor a) a)) + + extraRoots roots' = local (<> roots')