Function shapes and objects
A Function type describes a callable shape. A Function object is an instance of that shape, holding a checked method target and any bound receiver or captured environment. This page documents the structural family; “Function” is a documentation label, not a nominal type declaration.
Function types are another data-composition family: their structure is the callable signature rather than a nominal declaration. They retain their own Object and invocation contract; that does not impose reference semantics on tuples or unions. See all structural families.
Members
| Member | Contract |
|---|---|
| Invoke(P0, …): R | Calls the bound target with this shape's parameters and result. |
| Function: MethodInfo | Read-only property describing the closed bound target. |
| ToString(): String | Module-qualified target name and closed signature. |
| Equals(Object?): bool | Compares shape, closed target and receiver identity. |
| GetHashCode(): int | Hash consistent with value equality. |
GetMethods exposes Invoke, get_Function and the three synthesized Object overrides. GetProperties exposes Function. Object's GetType reports the actual signature even through an Object view. Applicable extension members are defined by their extension containers; they do not give the shape a nominal name.
Shape
Raven uses (P0, P1, ...) -> R (or () -> R without parameters). Ordered
parameter types and result type determine the shape. The native model also
preserves readonly/reference/output contracts and the no-result calling convention.
Matching display text alone does not establish identity: component types retain
their loaded identities. There is no named function type facility in this slice.
let first: (int) -> int = AddOne
let second: (int) -> int = Double
Both objects have the same structural shape while referring to different methods. Raven's current importer admits zero through four input parameters through CLI Func/Action metadata. Those carriers are compiler transport; they do not produce nominal delegate declarations in the runtime. Source unit results use the inhabited unit, including a generic result instantiated with unit. Binding a no-result method inserts the necessary unit-result adapter.
Invoke
For shape (P0, ..., Pn) -> R, Invoke(arg0: P0, ..., argn: Pn) -> R calls the
bound method and returns its result. Ordinary call syntax, such as first(41),
uses the same operation. Arguments must match the parameter contracts, and binding
an incompatible method is rejected during compilation or artifact validation.
The object retains its receiver/environment across collection. Frame-bound
references cannot escape through a retained Function object.
Structural types can have members and extension members. For example:
public extension FunctionExtensions for (int) -> int {
func Twice(value: int) -> int {
return self(self(value))
}
}
This adds an extension to the shape without giving the type a nominal name. The migration fixture contains the complete source examples and tracks their current validation.
Introspection and limits
typeof((int) -> int) returns common TypeInfo. IsNominalType is false; the
descriptor has no NominalTypeInfo or MemberInfo view. DisplayName is diagnostic
shape text. Member queries remain part of TypeInfo; absence of a declaration name
does not prohibit members or extensions. FunctionTypeInfo exposes Parameters and ReturnType directly. The
structural family browser includes this authored member
reference alongside the generated metadata reference.
The transport carrier types are explicitly excluded from generated type pages;
member signatures retain their matching CLI documentation IDs. Function equality compares shape, closed method and retained receiver identity.
Copies share captures; they do not copy a receiver. Default Function slots contain
null and Invoke faults with NullReference. Constructors must initialize their
Function fields before publication. Function objects inherit Object, support Object views and cast-back, and preserve
their precise signature through GetType. Separate bindings have separate reference
identity even when value-equal; copies retain reference identity.
There is no multicast combination or native function-pointer interop contract.
Use FunctionComparer and FunctionEqualityComparer to adapt callable values to
comparison contracts. The legacy .delegate, delegate.bind and serialized
Delegate encodings are not accepted by this runtime contract.
Common TypeInfo member queries include the synthesized public instance Invoke.
TypeInfo.IsFunctionType identifies its structural signature descriptor. Narrow to
FunctionTypeInfo for direct Parameters and ReturnType access. Its
InvokeMethod property provides the member view of the same signature, so callers
can choose either path. No generalized function-info interface is introduced. Repeated queries
compare equal but need not share wrapper identity. Parameter names are empty and
positions and modes come from the signature.
Invoke and its parameters have no declaration module or metadata token: their optional properties return None, as does MethodInfo.DefinitionIndex. DeclaringType returns Some(the Function signature), and custom attributes are empty. Ordinary members expose optional metadata too; consumers must pattern-match it. This descriptive method does not support MethodReflectionExtensions.Invoke yet; use ordinary typed Function invocation to execute the bound target.
Future nominal function types
A future nominal function type may inherit an eligible structural Function shape. Two nominal function types sharing that shape would remain distinct and could not directly convert to each other solely on signature equality. Non-nominal types are not generally inheritable; permitted kinds need explicit rules. This proposal does not make Array, Tuple, Union or Intersection inheritable. Conversion/rebinding rules remain future design work.
Bound target property
Every Function signature synthesizes a read-only public instance property
Function: MethodInfo. Read it on a Function object to inspect the actual bound
method/function. The signature's FunctionTypeInfo.InvokeMethod continues to
represent Invoke; it is not the bound target. GetProperties() exposes Function,
and GetMethods() includes its get_Function accessor as well as Invoke.
All synthetic methods have absent module, token and definition-index metadata.
The synthetic property's legacy integer DefinitionIndex is -1 and is not a
metadata-table index; its module/token are absent. Dynamic execution of these
synthetic descriptors returns UnboundMetadata; use the typed property or invocation.
The target MethodInfo has its available module/token/definition information, closed parameter and result types, and a declaring type when the target has one. Necessary importer adapters can expose generated targets without source module/token metadata; those optional properties return None. Module functions have no DeclaringType. Their custom attributes and dynamic reflection invocation are not supported by the current type-based services. The descriptor describes the method independently of a bound receiver. Repeated reads return equal descriptors, without promising wrapper identity. Null Function property access raises NullReference.
Same signature means same Function type. Function objects are value bindings: the same closed target and receiver/capture identity compare equal, regardless of when the bindings were created. Different targets, generic instantiations or receivers differ. Equal computed results do not imply equal Function objects. A future common FunctionInfo interface is deferred; Function returns MethodInfo now.
Object members
Function types have Object as their BaseType while IsNominalType remains false. They synthesize virtual overrides of ToString(), Equals(Object?) and GetHashCode(), also discoverable through GetMethods. Typed and Object calls agree: Equals compares closed target and receiver identity, equal values hash equally, and ToString displays the module-qualified target name with its closed signature. GetType on an Object view returns the actual Function signature. Type tests and casts back require the exact compatible shape; a different signature does not become callable by casting. Object.ReferenceEquals compares binding creation identity, not value equality.
ToString does not invoke user code, inspect receiver state or serialize captures. Lambdas may display compiler-generated target names. The diagnostic spelling may evolve and is not an equality key. Imported source names are retained independently of lowered implementation names. Null member access raises NullReference. This Object inheritance contract applies to Functions; structural identity alone does not imply the same behavior for other type families.
FunctionReflection.Invoke (provisional API)
Integrated on neoCLR main with Raven codex/neoclr on 2026-10-16. Integration does
not freeze this API or imply a published release.
Import System.Runtime.Reflection.* and use
FunctionReflection:
static func Invoke(function: Object?, arguments: Object?[])
-> Result<Object?, ReflectionError>
The argument is an existing native structural function reference, retaining its bound
receiver/captures. Supply a non-null argument array, including an empty array for a
zero-parameter function. A successful call returns Ok with the boxed scalar result,
original reference, or null for a no-result call. Null reference arguments/results
are supported when the signature admits reference values.
| Result error | Meaning |
|---|---|
InvalidReceiver |
The value is null or is not a function. |
InvalidArguments |
Argument count or type does not match; a null argument array also rejects. |
UnsupportedType |
The function signature requires unsupported marshalling. |
Validation does not enter the target. Exact scalar boxes and assignable references
are supported; numeric coercion, optional arguments, ref/out copyback and arbitrary
value record/tuple/union marshalling are not. Faults raised by the function itself
propagate, rather than becoming ReflectionError. The Object overload does not
infer a return type; the generic overload below retains the signature explicitly.
The library uses neoCLR.Runtime.InvokeFunctionCheck followed by the checked
InvokeFunction primitive. The check returns a status without calling the function;
the invocation primitive retains its runtime checks. Interpreter/JIT/AOT validation
and restrictions are recorded in the fixture.
This does not turn a MethodInfo into a bound function or add multicast policy.
The native reflection slice now recovers the exact selected function shape through
an Object view's GetType. Raven typeof((int) -> int) emits a structural native type
token; it does not acquire a nominal Func identity. The retained sample checks
IsFunctionType, IsNominalType=false and type equality before dynamically forwarding
a callback as both an argument and a result. Interpreter/JIT/AOT return 42. This
qualification covers type identity and dynamic invocation; it does not claim new
AOT support for every MethodInfo snapshot/query or generic reflection operation.
Raven native function values can also be tested and captured using ordinary type
patterns, including generic signatures: if obj is () -> T { } and
() -> T callback => callback() in a match arm. Null and incompatible signatures
fail the test; a successful capture remains callable with its original receiver.
See the retained source consumer above. These are language operations over existing
function metadata, not additional reflection API members.
TypeInfo.IsInstanceOfType(Object?) also recognizes function values. In the native
profile, typeof((int) -> int).IsInstanceOfType(value) succeeds for that exact
function signature, independently of the bound receiver. Null, nominal objects and
functions with different parameter or return types do not match. The source consumer
compares obj is () -> T with typeof(() -> T).IsInstanceOfType(obj) for closed
generic instantiations, including mismatches and null. This qualification uses the
existing reflection API; it adds no coercion or function variance conversions.
Typed invocation and method signatures (development)
static func Invoke<T>(function: T, arguments: Object?[]) -> ReturnType<T> where T: func
System.Runtime.Reflection.FunctionReflection.Invoke<T> retains the structural
signature and returns its projected result. arguments must be a non-null array
of the exact arity, containing compatible references/nulls or exact scalar boxes.
The same marshalling limits as the Object overload apply. Successful no-result or
unit-returning invocation produces unit. Other supported results are cast/unboxed
to the projected type. Validation failures call Panic through carrier extraction;
target faults propagate. Task results are returned unchanged. The helper does not
aggregate multiple results or schedule work.
System.Introspection.MethodInfo.FunctionType: TypeInfo describes the complete
public signature. An unresolved whole-signature method returns its function-constrained
generic parameter descriptor. A closed method returns FunctionTypeInfo and exposes
ordinary GetParameters() and ReturnType. Those two queries call Panic when the
whole signature remains unresolved. The receiver is not part of the function shape.
The legacy CLI documentation bridge cannot encode a return-type projection; this manual member entry is the reference for the typed overload. The new signature forms require the matching native compiler/runtime. See Generics.