spectacle
spectacle copied to clipboard
Use `Managed` monad in CLI
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 Handle
s would be an improvement.
Some other ideas to consider:
-
Follow the
withFile
style instead ofopenFile
:-handleFrom :: OutputOpt -> IO Handle +withHandleFrom :: OutputOpt -> (Handle -> IO a) -> IO a
-
resourcet
is similar tomanaged
, but it lets you free resources early (managed
holds onto resources until you leave theManaged
monad).