Skip to content

Generics vs Sum Types #16490

Nov 20, 2022 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Hmmm... Vlang's sum types are already doing what you wish generics in Vlang to do (in the example), so the user is not missing that functionality. Additionally, what you appear to want to do with the generics example, can presently be done as below.

fn whatami<T>(a T)  {
	match typeof(a).name {
        'int' {println('int:$a')}
        'string' {println('string:$a')}
        else {println('other')}
	}
}

whatami<int>(10)

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@eptx
Comment options

@JalonSolov
Comment options

Answer selected by eptx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants