From 81f4d996882f2bfdbdb765dfc30ec3bb1955232c Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 8 May 2018 11:22:27 -0400 Subject: [PATCH] Define helpers to run actions with locally-updated ModuleInfo/PackageInfo. --- src/Control/Abstract/Context.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Control/Abstract/Context.hs b/src/Control/Abstract/Context.hs index 189898c50..069ce60a5 100644 --- a/src/Control/Abstract/Context.hs +++ b/src/Control/Abstract/Context.hs @@ -2,7 +2,9 @@ module Control.Abstract.Context ( ModuleInfo , PackageInfo , currentModule +, withCurrentModule , currentPackage +, withCurrentPackage ) where import Control.Effect @@ -15,6 +17,14 @@ import Prologue currentModule :: (Effectful m, Member (Reader ModuleInfo) effects) => m effects ModuleInfo currentModule = raise ask +-- | Run an action with a locally-replaced 'ModuleInfo'. +withCurrentModule :: (Effectful m, Member (Reader ModuleInfo) effects) => ModuleInfo -> m effects a -> m effects a +withCurrentModule = raiseHandler . local . const + -- | Get the currently evaluating 'PackageInfo'. currentPackage :: (Effectful m, Member (Reader PackageInfo) effects) => m effects PackageInfo currentPackage = raise ask + +-- | Run an action with a locally-replaced 'PackageInfo'. +withCurrentPackage :: (Effectful m, Member (Reader PackageInfo) effects) => PackageInfo -> m effects a -> m effects a +withCurrentPackage = raiseHandler . local . const