News for hackers. Stuff that matters.
Re:On Error Handling in Rust by jeremyjh on Thursday October 16, 2014 @11:22PM (#8469276)
I hope we get some sugar here, the ? operator is a great idea. I like the trait implementation as well. I think Rust needs multiple dispatch though - a given type needs to support conversions of IOError to different custom results right? So you can use a struct in different library functions that may return a different custom error. Or maybe I am missing something here; but I do believe multiple dispatch is planned for 1.0.

I did this in Haskell using MPTC, I have used the Convertible class like:

instance Convertible IOError RedisError where safeConvert = <conversion mapping here>

Then I have combinators like:

convEither :: Convertible e1 e2 => Either e1 a -> Either e2 a

and

convEitherT :: Convertible e1 e2 => m (Either e1 a) -> EitherT m e2 a

These are quite handy in close quarters combat. For example to open a file and bail on a generic IOException with a custom application exception, I can have something like:

instance Convertible IOException CustomError

getWords :: FilePath -> IO (Either CustomError [String])

getWords fileName = runEitherT $

    do file <- tryIO (openFile fileName) >>= convEitherT

       line <- readLine file 
       return (words line)
Re:On Error Handling in Rust by dtwwtd on Friday October 17, 2014 @01:48AM (#8469582)
Re:On Error Handling in Rust by kibwen on Friday October 17, 2014 @09:43AM (#8470892)
Multidispatch traits are being implemented as we speak, and you are correct that this whole discussion is blocked on them (they are mentioned in the first RFC linked, the one discussing `FromError`).
Re:On Error Handling in Rust by m0th87 on Thursday October 16, 2014 @11:35PM (#8469318)
Doesn't multiple dispatch require run-time type analysis? If so wouldn't that go against Rust's philosophy of zero-cost abstractions?
Re:On Error Handling in Rust by carterschonwald on Thursday October 16, 2014 @11:52PM (#8469356)
nope, its all compile time. its just that instead of deciding which impl to pick based upon information X, youre using a pair of pieces of information (X,Y)

Edit, also I think the "convertable" class idea is nearly expressible using associated types in rust today,but im not 100% certain about that

Re:On Error Handling in Rust by m0th87 on Friday October 17, 2014 @08:20AM (#8470522)
Wikipedia implies that multiple dispatch is done by run-time time analysis in OO languages, which does not apply to Haskell or Rust: https://en.wikipedia.org/wiki/Multiple_dispatch

Maybe it's being pedantic, but I can't tell. Are Haskell's type classes strictly as flexible as multiple dispatch?

Re:On Error Handling in Rust by twic on Saturday October 18, 2014 @09:01AM (#8475252)
The proposed Rust feature sounds like overloading rather than multiple dispatch as it is usually understood.
Re:On Error Handling in Rust by kibwen on Friday October 17, 2014 @09:48AM (#8470928)
Rust's upcoming support for multidispatch traits is all strictly static.