Completed
Next steps The Go team is actively pursuing a real implementation (in a branch) so we can iron out any outstanding open problems.
Class Central Classrooms beta
YouTube videos curated by Class Central.
Classroom Contents
Typing Generic Go
Automatically move to the next video in the Classroom when playback concludes
- 1 Intro
- 2 Type parameters draft design
- 3 A type parameter list
- 4 Type parameters to the rescue
- 5 Constraints • A constraint specifies the requirements which a type argument must satisfy
- 6 Declaration and scope of type parameters type parameter declaration
- 7 Type-checking the Sort call: Instantiation
- 8 Type-checking the Sort call: Invocation
- 9 Type-checking a generic call 1 Instantiation (new) • replace type parameters with type arguments in entire signature • verify that each type argument satisfies its constraint
- 10 Separating instantiation from invocation booksort :- Sort[book] // == #Sort book booksort (bookshelf)
- 11 Sort internals
- 12 Type-checking a generic call (refined) 1. If no type arguments are provided: Use argument type inference to infer type arguments.
- 13 What is missing? So far, constraints can only describe method requirements.
- 14 Type lists A constraint interface may have a list of types (besides methods)
- 15 Satisfying a type list An argument type satisfies a constraint with a type list if
- 16 Different type parameters are different types
- 17 Example: Combining byte and string operations type Bytes interface type []byte, string
- 18 Example: Relationships between type parameters type Pointer T any interface The type argument for PT must be a
- 19 Summary Declarations Type parameter lists are like ordinary parameter lists with TT • Function and type declarations may have type parameter lists • Type parameters are constrained by interfaces
- 20 How happy are we with this design? • Type parameters • Interfaces as constraints • Type lists in interfaces
- 21 With great power comes great responsibility • Type parameters ('generics ) are a new tool in the toolset of Go. • Orthogonal to the rest of the language. • Orthogonality opens a new dimension of codi…
- 22 Examples (1)
- 23 When to use generics
- 24 Next steps The Go team is actively pursuing a real implementation (in a branch) so we can iron out any outstanding open problems.