Re:The Updated Draft Design for Go 2 Contracts
by ithkuil on Saturday July 27, 2019 @08:32PM
(#20545156)
"var n int" means "in this scope, declare variable n to be if type int".
"type T adder" means "in this scope, declare T to be a type adhering to the adder contract"
Re:The Updated Draft Design for Go 2 Contracts
by dilap on Saturday July 27, 2019 @11:07PM
(#20545632)
Good way to think of it.
Re:The Updated Draft Design for Go 2 Contracts
by DangitBobby on Saturday July 27, 2019 @08:14PM
(#20545081)
I think calling it a type would be confusing. It's not a type, it's a description of a behaviors of potential types.
I was wondering about this too. It also just feels really weird since it's a different construction than any of the other types.
Maybe the thinking is because a contract is not a type? But so what...
On first blush, it also feels weird that type is coming _before_ the type arguments, rather than after -- since types for normal arguments come after the argument.
E.g.,
feels much more consistent than no? (Perhaps it complicates parsing, though?)