Last active
June 28, 2020 17:39
-
-
Save aweary/7ad7998adfb6ead94a891a0e7d12f8cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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