Note that there are some explanatory texts on larger screens.

plurals
  1. POMonad transformer for progress tracking
    text
    copied!<p>I am looking for a monad transformer that can be used to track the progress of a procedure. To explain how it would be used, consider the following code:</p> <pre><code>procedure :: ProgressT IO () procedure = task "Print some lines" 3 $ do liftIO $ putStrLn "line1" step task "Print a complicated line" 2 $ do liftIO $ putStr "li" step liftIO $ putStrLn "ne2" step liftIO $ putStrLn "line3" -- Wraps an action in a task task :: Monad m =&gt; String -- Name of task -&gt; Int -- Number of steps to complete task -&gt; ProgressT m a -- Action performing the task -&gt; ProgressT m a -- Marks one step of the current task as completed step :: Monad m =&gt; ProgressT m () </code></pre> <p>I realize that <code>step</code> has to exist explicitly because of the monadic laws, and that <code>task</code> has to have an explicit step number parameter because of program determinism/the halting problem.</p> <p>The monad as described above could, as I see it, be implemented in one of two ways:</p> <ol> <li>Via a function that would return the current task name/step index stack, and a continuation in the procedure at the point that it left off. Calling this function repeatedly on the returned continuation would complete the execution of the procedure.</li> <li>Via a function that took an action describing what to do when a task step has been completed. The procedure would run uncontrollably until it completed, "notifying" the environment about changes via the provided action.</li> </ol> <p>For solution (1), I have looked at <code>Control.Monad.Coroutine</code> with the <code>Yield</code> suspension functor. For solution (2), I don't know of any already available monad transformers that would be useful.</p> <p>The solution I'm looking for should not have too much performance overhead and allow as much control over the procedure as possible (e.g. not require IO access or something).</p> <p>Do one of these solutions sound viable, or are there other solutions to this problem somewhere already? Has this problem already been solved with a monad transformer that I've been unable to find?</p> <p><strong>EDIT:</strong> The goal isn't to check whether all the steps have been performed. The goal is to be able to "monitor" the process while it is running, so that one can tell how much of it has been completed.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload