spectacle icon indicating copy to clipboard operation
spectacle copied to clipboard

Use `Managed` monad in CLI

Open riz0id opened this issue 3 years ago • 1 comments

Currently Language.Spectacle.Interaction.Options uses a file Handle to write model checker logs to a file if the user provides an output path with --output/-o and is subsequently closed when CLI is completed in Language.Spectacle.Interaction.CLI.

Manually managing this handle is error-prone. @ixmatus noted using the Managed monad to handle cleanup of file Handles would be an improvement.

riz0id avatar Feb 03 '22 19:02 riz0id

Some other ideas to consider:

  • Follow the withFile style instead of openFile:

    -handleFrom :: OutputOpt -> IO Handle
    +withHandleFrom :: OutputOpt -> (Handle -> IO a) -> IO a
    
  • resourcet is similar to managed, but it lets you free resources early (managed holds onto resources until you leave the Managed monad).

evanrelf avatar Feb 03 '22 20:02 evanrelf