On Wed, Aug 17, 2022 at 10:43 AM Brian Candler <b.cand...@pobox.com> wrote:
> That's an interesting paper - at least the early parts that I could > understand! > > I tried converting <https://go.dev/play/p/yJvOncevnoP> their main > motivating example from fig 8, but got stuck by not being able to put a > method on a parameterised type: > > func (e Plus[a Evaler]) Eval() int { > return e.left.Eval() + e.right.Eval() > } > // ./prog.go:21:16: syntax error: unexpected Evaler, expecting ] > > func (e Plus[Evaler]) Eval() int { > return e.left.Eval() + e.right.Eval() > } > // ./prog.go:24:16: e.left.Eval undefined (type Evaler has no field or > method Eval) > // ./prog.go:24:33: e.right.Eval undefined (type Evaler has no field or > method Eval) > > func (e Plus[a]) Eval() int { > return e.left.Eval() + e.right.Eval() > } > // ./prog.go:24:16: e.left.Eval undefined (type a has no field or method > Eval) > // ./prog.go:24:33: e.right.Eval undefined (type Evaler has no field or > method Eval) > > Is this what is meant by: > > > *Another result is the proposal for covariant receiver typing, a feature > required by The Expression Problem. It is not part of the Go team’s current > design, but they have noted it is backward compatible and are considering > adding it in the future.* > > ? > Yes, that's what is meant by that. Though the issue is not putting a method on a parameterized type - you can do that. And it's not even putting a method with extra type parameters on a type - you can't do that and it doesn't seem possible under the current design restrictions put on generics in Go. But to have a method with a receiver more tightly constrained than the type itself (personally, I've been calling that "refined method constraints", in lieu of a better term). That seems an entirely possible future extension. But not yet. We should first try out generics as they are for a while. > -- > 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/528c0c73-e2db-4153-a505-6003deb886f2n%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/528c0c73-e2db-4153-a505-6003deb886f2n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CAEkBMfFh2Ln-136u6tfx%2BgUULVM1U6AVqE7C3R5a7fMUiwyQsQ%40mail.gmail.com.