Skip to content

language: covariance support #7512

Closed
Closed
@gopherbot

Description

@gopherbot

by justin@fathomdb.com:

Go does not support contravariance, specifically

type Iterator interface {
  Next() interface{}
}

is not satisfied by

func (s*WidgetList) Next() *Widget

---

Supporting contravariance would:

* Reduce the complexity of the language for the programmer (people assume things are
contravariant, covariance is more nuanced).

* Enable good collection classes to be implemented, which would likely either reduce the
need for generics or point the way.

* Should not be slower to compile than a call to Next().(*Widget).  It may actually be
faster, by allowing better caching.

* Be reasonable in terms of implementation difficulty.



I couldn't find a bug tracking this, so I'm opening this one!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions