Why does Shake not provide a MonadMask instance for Action?

145 Views Asked by At

I would like to use the temporary package with Shake, but that requires Action to have an instance for MonadMask, which is missing. Why does Shake not provide such an instance?

1

There are 1 best solutions below

0
On BEST ANSWER

There are two reasons:

  • It's impossible, since Action is based on a continuation monad, and you can't implement MonadMask for a continuation monad. See this blog post for a rough justification of why that is impossible.
  • It's undesirable, since then you could make choices depending on whether a dependent rule succeeds or fails, whereas in Shake the failure of a rule you depend on should always result in you failing.

However, Shake does provide actionFinally and actionOnException as building blocks, which are a restricted variant of the functions available in MonadMask. In addition, Shake provides withTempFile and withTempDir, which do some of the same things as the temporary package. And finally, if you are entirely in IO, then liftIO and bracket works fine.