multi

package
v0.0.0-...-2561dba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RegisteredFuncs = make(map[string]*Scaffold) // must initialize

RegisteredFuncs maps a function name to the corresponding function scaffold.

Functions

func ModuleRegister

func ModuleRegister(module, name string, scaffold *Scaffold)

ModuleRegister is exactly like Register, except that it registers within a named module. This is a helper function.

func Register

func Register(name string, scaffold *Scaffold)

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.

func (*Func) Build

func (obj *Func) Build(typ *types.Type) (*types.Type, error)

Build is run to turn the maybe polymorphic, undetermined function, into the specific statically typed version. It is usually run after unification completes, and must be run before Info() and any of the other Func interface methods are used.

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

type WrappedFunc = wrapped.Func

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL