On 12/20/11 2:55 PM, Elly Jones wrote:
This is okay, but it's an operation I do a _lot_, so I'd sort of like a lighter
syntax for it, like:

let bar(mybar) = foo else { fail "OOPS"; }

With the restriction that the else {} block may not continue execution, I don't
think this is terribly semantically incoherent.

If I may ask, why are you doing this so often? Is it that you often write functions which are handling a specific case of a tag and you pass in the tag value to the function, then need to extract the relevant data?

I do find it happens frequently that, in a particular context, I know that the tag value may only take on some subset of the possible variants. I would personally like to find a way to extend the type system to let me express that (and thus prove that my intuition is true). I think we shouldn't have to write `fail "OOPS"` except in extreme cases. Scala's case classes offer such flexibility but maybe there is a lighter way to get something similar.

Anyhow, can you maybe point me at some of the code where you find a need for extracting a particular variant in this way?


Niko
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to