Skip to content

Commit 9183c4c

Browse files
committed
Small change to 'rules' smart constructor
Wrapping the function type in 'StaticPtr' made impossible some higher-order patterns, such as those used by the doctest library. So we instead have a separate 'StaticPtr label' argument for the namespacing.
1 parent 701c36a commit 9183c4c

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

proposals/0000-replacing-cabal-custom-build.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ data Rule
10751075
, staticDependencies :: ![Dependency]
10761076
-- ^ Static dependencies of this rule.
10771077
, results :: !(NE.NonEmpty Location)
1078-
-- ^ Results of this rule; see t'Result'.
1078+
-- ^ Results of this rule.
10791079
}
10801080
deriving (Eq, Binary)
10811081

@@ -1108,7 +1108,7 @@ instance Eq (Command arg res)
11081108
instance Binary (Command arg res)
11091109

11101110
newtype Rules env =
1111-
Rules { runRules :: env -> RulesT IO () }
1111+
Rules { runRules :: env -> RulesM () }
11121112
```
11131113

11141114
In this design, a rule stores a closure (in the sense of Cloud Haskell) that
@@ -1123,7 +1123,7 @@ rule (with no dynamic dependencies), this constists of:
11231123
For example, the function might be an invocation of `happy` whose arguments
11241124
depend on the passed in value (e.g. which module we are compiling).
11251125

1126-
The specific monadic return type, `RulesT IO ()`, is used internally to handle
1126+
The specific monadic return type, `RulesM ()`, is used internally to handle
11271127
generation of `RuleId`s as explained in [§ Identifiers](#identifiers).
11281128
Ignoring these implementation details, we can think of the rules as being
11291129
specified by a Haskell function with the following type:
@@ -1393,7 +1393,7 @@ executions of the `IO` action that computes the set of pre-build rules.
13931393
We propose that users generate `RuleId`s themselves with the following API:
13941394

13951395
```haskell
1396-
registerRule :: ShortText -> Rule -> RulesT IO RuleId
1396+
registerRule :: ShortText -> Rule -> RulesM RuleId
13971397
```
13981398

13991399
The `ShortText` argument is a user-given name for the rule. Different rules
@@ -1422,7 +1422,7 @@ whenever these change, the rules as a whole are recomputed.
14221422
The basic API function is
14231423

14241424
```haskell
1425-
addRuleMonitors :: Monad m => [ MonitorFileOrDir ] -> RulesT m ()
1425+
addRuleMonitors :: [ MonitorFileOrDir ] -> RulesM ()
14261426
```
14271427

14281428
where `MonitorFileOrDir` is some datatype, such as the one that exists in
@@ -1451,18 +1451,18 @@ data Rules env -- definition not exposed to the user
14511451
instance Semigroup (Rules env)
14521452
instance Monoid (Rules env)
14531453

1454-
rules :: StaticPtr (env -> RulesT IO ()) -> Rules env
1454+
rules :: StaticPtr label -> (env -> RulesM ()) -> Rules env
14551455

14561456
data RuleId
14571457
-- In practice, identifiers consists of a pair of a UnitId and
14581458
-- a user-supplied textual name, but the constructor is crucially
14591459
-- not exposed in the API in order to enforce hygiene.
14601460

1461-
newtype RulesT m a
1461+
newtype RulesM a
14621462
deriving (Functor, Applicative, Monad, MonadTrans, MonadIO, MonadFix)
14631463

1464-
registerRule :: ShortText -> Rule -> RulesT IO RuleId
1465-
addRuleMonitors :: [ MonitorFileOrDir ] -> RulesT IO ()
1464+
registerRule :: ShortText -> Rule -> RulesM RuleId
1465+
addRuleMonitors :: [ MonitorFileOrDir ] -> RulesM ()
14661466
```
14671467

14681468
To illustrate, we might implement the `c2hs` preprocessor using this
@@ -1473,9 +1473,9 @@ framework (from [§ Dynamic dependencies](#dynamic-dependencies)) as follows:
14731473
{-# LANGUAGE StaticPointers #-}
14741474

14751475
c2HsPreBuildRules :: PreBuildComponentRules
1476-
c2HsPreBuildRules = rules $ static c2HsRules
1476+
c2HsPreBuildRules = rules (static ()) c2HsRules
14771477

1478-
c2HsRules :: PreBuildComponentInputs -> RulesT IO ()
1478+
c2HsRules :: PreBuildComponentInputs -> RulesM ()
14791479
c2HsRules buildEnvt = mdo
14801480

14811481
(chsModDirs :: Map ModuleName FilePath)
@@ -1534,8 +1534,7 @@ Here, the Hooks API uses static pointers in order to tag rules by the package th
15341534
defines them, in order to allow combining the `Rules` declared by two different
15351535
libraries, as described in [§ Composing `SetupHooks`](#composing-setuphooks).
15361536
The user-provided names for rules (`"r1"`, `"r2"`, `"r3"` above) are expected
1537-
to be unique within the package that defines them (note that this is stronger
1538-
than requiring uniqueness in the `static` block that contains them).
1537+
to be unique (within the scope of the label).
15391538
(NB: we don't use `static` for each individual identifier, as these are often
15401539
dynamically generated based on the result of an `IO` action, as above.)
15411540

0 commit comments

Comments
 (0)