Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var RegisteredFuncs = make(map[string]*Scaffold) // must initialize
RegisteredFuncs maps a function name to the corresponding function scaffold.
Functions ¶
func ModuleRegister ¶
ModuleRegister is exactly like Register, except that it registers within a named module. This is a helper function.
func Register ¶
Register registers a simple, static, pure, polymorphic function. It is easier to use than the raw function API. It allows you to build and check a function based on a type signature that contains unification variables. You may only specify a single type signature with the API, so some complex patterns are not possible with this API. Implementing a function like `printf` would not be possible. Implementing a function which counts the number of elements in a list would be.
func TypeMatch ¶
func TypeMatch(m map[string]interfaces.FuncSig) func(*types.Type) (interfaces.FuncSig, error)
TypeMatch accepts a map of possible type signatures to corresponding implementing functions that we want to check against after type unification. On success it returns the function who's corresponding signature matched. This helper function returns a function which is suitable for use in the scaffold make function field.
Types ¶
type Func ¶
type Func struct { *docsUtil.Metadata *WrappedFunc // *wrapped.Func as a type alias to pull in the base impl. // Make is a build function to run after type unification. It will get // passed the solved type of this function. It should error if this is // not an acceptable option. On success, it should return the // implementing function to use. Of note, this API does not tell the // implementation what the correct return type should be. If it can't be // determined from the input types, then a different function API needs // to be used. XXX: Should we extend this here? Make func(typ *types.Type) (interfaces.FuncSig, error) }
Func is a scaffolding function struct which fulfills the boiler-plate for the function API, but that can run a very simple, static, pure, polymorphic function. This function API is unique in that it lets you provide your own `Make` builder function to create the function implementation.
type Scaffold ¶
type Scaffold struct { // T is the type of the function. It can include unification variables. // At a minimum, this must be a `func(?1) ?2` as a naked `?1` is not // allowed. (TODO: Because of ArgGen.) T *types.Type // M is a build function to run after type unification. It will get // passed the solved type of this function. It should error if this is // not an acceptable option. On success, it should return the // implementing function to use. Of note, this API does not tell the // implementation what the correct return type should be. If it can't be // determined from the input types, then a different function API needs // to be used. XXX: Should we extend this here? M func(typ *types.Type) (interfaces.FuncSig, error) // D is the documentation handle for this function. We look on that // struct or function for the doc string. D interface{} }
Scaffold holds the necessary data to build a (possibly polymorphic) function with this API.
type WrappedFunc ¶
WrappedFunc is a type alias so that we can embed `wrapped.Func` inside our struct, since the Func name collides with our Func field name.