Why no `Action a -> Rules a` function

29 Views Asked by At

In Shake there is a way to run an Action from Rules:

action :: Action a -> Rules ()

But I couldn't find a function which returns the result of the Action, namely:

actionWithResult :: Action a -> Rules a

How come?

1

There are 1 best solutions below

0
Neil Mitchell On

The reason is that Rules is run first, to completion, and then Actions are run - so it's somewhat staged programming. All action does is records an Action, to execute later. The reason you have to run all the Rules first is so that it can collect all the possible types of rule that are available, since they're all available for all Actions.

Once you understand the staging, it's impossible to have Action a -> Rules a, because that implies running an Action and returning the result to Rules, so Action must run before Rules completes. However, Actions a -> Rules () is fine, because it doesn't actually run then, but later.