I agree. constraint is different from normal interface. It's better to use 
type SomeConstraint constraint {} than  type SomeConstraint interface {} 

On Wednesday, June 17, 2020 at 11:12:24 AM UTC+8 Brandon Dyck wrote:

> I find it a little strange that an interface with a type list can only be 
> used as a constraint, and not as the type of a variable or parameter, 
> despite it using basically the same syntax as a normal interface. Is this 
> difference between constraints and other interfaces a property of the type 
> system, or just a limitation of the translation? I don't think it was 
> explicit in the design document. It would certainly be useful to declare 
> variables with type-list interfaces, as it would provide a much less hacky 
> way to define sum types than using an unexported interface method as in 
> https://medium.com/@haya14busa/sum-union-variant-type-in-go-and-static-check-tool-of-switch-case-handling-3bfc61618b1e
> .
>
> My failing example is at https://go2goplay.golang.org/p/-lQ0jKs8_hU.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/88aa126b-d8f1-49c0-84cd-c0ea8cd87d39n%40googlegroups.com.

Reply via email to