|
|
|
|
|
by adamthekiwi99
899 days ago
|
|
Hello, thanks for the great question! Yes, you do have to specify where a variant comes from, but it doesn't have to be nominal at all! Here's an example: ```
enum Option<T> {Some(T), Nothing} // Create a value with an inline type that doesn't use the nominal `Option` let opt1 = enum {Some(Int), Nothing} of Some(5); // Define a second option value, which is assigned with the first let opt2: Option<Int> = opt1; // Print the result println(opt2);
``` You can create a variant of an inline `enum` type, and then typecheck it against another structurally equal type if you so choose! I hope this example properly illustrates how powerful the structural type-checking is with enums! |
|