Skip to content

Instantly share code, notes, and snippets.

View andybalholm's full-sized avatar

Andy Balholm andybalholm

  • Northland Computer Services
  • Clayton, Washington
View GitHub Profile
@andybalholm
andybalholm / contracts_adaptors.md
Last active October 30, 2019 19:42
Contracts and Adaptors

Contracts and Adaptors

This is a proposal for an alternate syntax for contracts for generics in Go, along with adaptors for types that do not natively fulfill the contract. It takes a lot of inspiration from Pat Smith's Go Generics with Adaptors.

It is primarily motivated by the discussion about how to make a single generic function work both with builtin types that use operators and with user-defined types that use methods.

Contracts

@andybalholm
andybalholm / contracts.md
Last active October 26, 2018 17:36
Enumerated and structural contracts

(This is a refinement of Burak Serdar's proposal at https://gist.github.com/bserdar/8f583d6e8df2bbec145912b66a8874b3)

Enumerated Contracts

The simplest way to specify a contract is to provide a list of the types that fulfill it:

contract byteSequence string, []byte
contract unsigned uint, uint8, uint16, uint32, uint64, uintptr
contract signed int, int8, int16, int32, int64