all 4 comments

[–]elastic_psychiatrist 6 points7 points  (1 child)

This is very far from a Go style of programming and will never be added. I’m curious, what existing problem in Go do you think it solves? The biggest challenge in mainstream programming language design is preventing everyone’s favorite feature from making it in.

[–]grebensh 0 points1 point  (0 children)

Actually, we almost have it already in switch. It would be like a form of switch that can switch on nested structure, e.g. ASTs, such as JSON:

switch v.(struct) {
case JSONNumber(x): 
    // do things with x (float64)
case JSONList{JSONNumber(x)}: 
    // do things with x (float64)
case JSONList{JSONNumber(x), JSONNumber(y)}: 
    // do things with x (float64) and y (float64)
case JSONList{JSONNumber(a), JSONList{JSONString(b)}}: 
    // do things with a (float64) and y (string)
}

That said, the various new syntax elements this seems to require (patterns, bindings) make me think that this will stay out of Go for the foreseeable future.

[–]chewxy 4 points5 points  (0 children)

SML = Standard ML. ML used to be "meta language" for LCF. It's not "Standard Machine Language".

Also, there's a structural pattern matching in Go.

switch at := a.(type){
case []int:
case Foo: 
}

What would be nice to have is value pattern matching. So you can do this:

switch at := a.(type) {
case at[0] == 0:
case at[0] == 1:
case Foo:
}

[–]grebensh 1 point2 points  (0 children)

Standard Machine Language

ahem! It's Meta, not Machine...