-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 11/15/11 12:47 AM, Niko Matsakis wrote:
>
> On Nov 14, 2011, at 12:53 PM, Brian Anderson wrote:
>
>> std has a 'result::t<T, U>' type that I am trying to use for this
>> purpose. std::io makes use of this now.
>
> Besides exceptions, I do not have a better alternative than
> `std::result`. However, I fear that if we go too far down this
> style, it will very painful and we will find ourselves wishing for
> syntactic sugar to support chaining (whether that is monads or
> something else). At least this has been my experience when working
> in OCaml.
>
> Are we sure that we do not want exceptions?
Actually, since we have `ret`, I'm sure that we can have small
syntactic sugar without resorting to monads.
Assuming we have,
foo(x: str) -> result::t<T, U> { ... }
We could write
let x = #result[foo(y)]
And expand it to
let x = {
let __result = foo(y);
alt(__result) {
ok(z) { z }
err(_){
//Possibly add some logging here
ret __result
}
}
}
In practice, this is already what happens in mozilla-central. Not
ideal, but probably easier to sell to non-fp users as monads, and it
takes advantage of `ret`. I wonder about performance, though. Is there
a way that the compiler could recognize this pattern and somehow
optimize it to attain the same kind of performance as exceptions?
Cheers,
David
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
iQEcBAEBAgAGBQJOwhdqAAoJED+FkPgNe9W+AMoH/i5scrjiLO2tyscpUcrc3+x5
682VB3aoKN30ddmZDWMbtFSDTMpRERfoNWlNIYtkL0fB5jnw+jyVibPIHzEzArsd
p+VlXLicPizWHywvIKsNcIkJs2kcQOVP/GQ8BM3XccvnU4I17mYBRWWHsNLtQEFG
YVNmHplLp3bSFORST+R9ZxG+ToTzmhPWCDWmqJECJnSkTj4owlyKd223XyqgYacG
NV9eZFbfTTV94m7hgu9shSIWzfbV7KG2JLbGzMCFT1wb8AK6+uZvQohjXbAe+u9G
yk6KGaoF4JDo02osH/cf9CY1t23sOBAHfzTfb8BKjnHF+pce6LrYa5gZTWGZ9c4=
=87nd
-----END PGP SIGNATURE-----
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev