The Next Step for Generics

9 months ago - Direct link

Introduction


It’s been almost a year since we last wrote about the possibility of
adding generics to Go
.
It’s time for an update.



Updated design


We’ve been continuing to refine the generics design
draft
.
We’ve written a type checker for it: a program that can parse Go code
that uses generics as described in the design draft and report any
type errors.
We’ve written example code.
And we’ve collected feedback from many, many people—thanks for
providing it!


Based on what we’ve learned, we’re releasing an updated design
draft
.
The biggest chan...


Go to article →

Links in this thread

Why Generics? - The Go Blog
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.


Contracts — Draft Design
We will not be pursuing the approach outlined in this design draft. It has been replaced by a new design draft. This document exists for historical context.


Type Parameters - Draft Design
We suggest extending the Go language to add optional type parameters to types and functions. Type parameters may be constrained by interface types. We also suggest extending interface types, when used as type constraints, to permit listing the set of types that may be assigned to them. Type inference via a unification algorithm is supported to permit omitting type arguments from function calls in many cases. The design is fully backward compatible with Go 1.


The go2go Playground
The go2go Playground is a web service that runs on golang.org's servers. The service receives a Go program, vets, compiles, links, and runs the program inside a sandbox, then returns the output.


Installing Go from source - The Go Programming Language
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.


dev.go2go branch
This branch contains a type checker and a translation tool for experimentation with generics in Go. This implements the generics design draft.


golang/proposal
Go Project Design Documents. Contribute to golang/proposal development by creating an account on GitHub.


golang/go
The Go programming language. Contribute to golang/go development by creating an account on GitHub.


Featherweight Go
We describe a design for generics in Go inspired by previous work on Featherweight Java by Igarashi, Pierce, and Wadler. Whereas subtyping in Java is nominal, in Go it is structural, and whereas generics in Java are defined via erasure, in Go we use monomorphisation. Although monomorphisation is widely used, we are one of the first to formalise it. Our design also supports a solution to The Expression Problem.


rhu1/fgg
Mini prototype of FG/FGG/FGR in Go. Contribute to rhu1/fgg development by creating an account on GitHub.


Type Parameters - Draft Design
We suggest extending the Go language to add optional type parameters to types and functions. Type parameters may be constrained by interface types. We also suggest extending interface types, when used as type constraints, to permit listing the set of types that may be assigned to them. Type inference via a unification algorithm is supported to permit omitting type arguments from function calls in many cases. The design is fully backward compatible with Go 1.