Skip to content

Instantly share code, notes, and snippets.

@aweary
Last active June 28, 2020 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aweary/7ad7998adfb6ead94a891a0e7d12f8cf to your computer and use it in GitHub Desktop.
Save aweary/7ad7998adfb6ead94a891a0e7d12f8cf to your computer and use it in GitHub Desktop.
// Option is a simple example of an enum
// that is generic, with a variant that doesn't
// use that generic type. (None)
enum Option<T> {
Some(T),
None,
}
// Two functions that take different types of `Option`s
fn with_option_string(input: Option<string>) {}
fn with_option_number(input: Option<number>) {}
fn main(numerator, denominator) {
// What is the type of `none`? Right now it's
// `Option<?>` because we can't refine it yet...
let none = Option.None;
// This would refine it to `Option<string>`
with_option_string(none);
// But should this work? `Option.None` is still
// a valid value, but the refinement above would
// cause a type error.
with_option_number(none);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment