[Haskell-cafe] error handling (esp. IO/exceptions)

Miguel Mitrofanov miguelimo38 at yandex.ru
Tue Apr 14 15:36:06 EDT 2009


What about ErrorT monad transformer? Well, if it's not what you really  
want, you can define your own one without ugly "Error" class, so it'd  
be something like

execute :: FilePath -> [String] -> MyCoolErrorT ExecuteError IO ExitCode

On 14 Apr 2009, at 23:29, brian at lorf.org wrote:

> I'm finding it hard to write robust code that isn't really ugly.  
> Suppose
> I want to write
>
>> execute :: FilePath -> [String] -> IO (Either ExecuteError ExitCode)
>
> where 'ExecuteError' is a data type representing all the ways  
> 'execute'
> could fail and that 'execute p args' is supposed to
>
> * ensure p exists
> * get p's permissions
> * ensure p is readable
> * ensure p is executable
> * execute p and return its exit code
>
> So 'ExecuteError' would have constructors corresponding to these  
> ways to
> fail:
> * could not determine whether p exists
> * p does not exist
> * could not get p's permissions
> * p is not readable
> * p is not executable
> * could not execute p for some other reason
>
> So if I start to code it, I 'tryJust' 'doesFileExist'. If an exception
> is thrown, I convert it to Left $AppropriateExecuteError. If not, we
> know whether p exists. If it doesn't, convert it to Left. Otherwise,
> 'tryJust' 'getPermissions', etc. It's starting to staircase.
>
> I'm needing it to be easier to stop my computation and return specific
> things when exceptions are thrown or when certain requirements aren't
> met. Thanks for any help.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list