I don’t see how removing the explicit variant would impede use of this syntax with “custom” types in the future.
Instead of having to specify which variant we unwrap in the let?
you could have an annotation in the type saying which one unwraps with let?
.
I think the main question is: Does it make sense to use let?
with Error
or with None
?
If it makes sense, then having to specify the variant in let? Error(err)
would make sense because some times you may want to unwrap one or the other variant and return the other one.
If it doesn’t make sense, having to specify Ok
or Some
all the time is just noise.
Just for comparison, here is what the ?
operator would look like in rust, with the example in the first post:
async fn get_user(id: u32) -> Result<User, UserError> {
let user = fetch_user(id).await?;
let decoded_user = decode_user(user).await?;
println!("Got user {}!", decoded_user.name);
ensure_user_active(&decoded_user).await?;
Ok(decoded_user)
}
Compare to
let getUser = async (id) => {
let? Ok(user) = await fetchUser(id)
let? Ok(decodedUser) = decodeUser(user)
Console.log(`Got user ${decodedUser.name}!`)
let? Ok() = await ensureUserActive(decodedUser)
Ok(decodedUser)
}
It is very very close, except for the Ok redundancy.
So I think once the question is clearly answered, the design falls off the decision: Does it make sense to use let?
with Error
or with None
?
From my personal opinion, let?
should work always the same with a certain type, and for result
it is by unwrapping Ok
and returning Error
, same for option. Given this, removing the variant in the left side of the assignment would make code nicer.
In any case, as proposed, I still think this would be great, and this is just splitting hairs. Full support for this.