Skip to content

The reflect library

tim-hardcastle edited this page Jun 10, 2025 · 1 revision

Introduction

While many of the Pipefish standard libraries closely parallel the Golang standard libraries, the Pipefish reflect library is necessarily very different from the Go reflect library in all but name, since the Pipefish type system is different from Go its semantics.

The library is also somewhat different in its purpose. Being (slightly) more dynamic than Go, Pipefish has already built-in ways of doing dynamic things to values, using such things as the type and keys functions and the in operator.

So what the reflect library allows you to do beyond that is find the properties of types, and so all the functions of the reflect library take as their arguments things of the built-in type type.

Functions

  • contains(t, subtype type) -> bool

Returns true if the second type is a subtype of the first.

  • elements(t type) -> list

A list of the elements of a clone type; return an error if the type is not concrete or not a clone.

  • isAbstract(t type) -> bool

Returns true if the type is abstract, i.e. if it is the union of more than one (or of zero) concrete types.

  • isBuiltin(t type) -> bool

Returns true if the type is neither a struct, an enum, or a clone, e.g. int, list, error, pair, etc. Returns an error if the type is abstract.

  • isClone(t type) -> bool

Returns true if the type is a clone, and an error if it's abstract.

  • isConcrete(t type) -> bool

Returns true if the type is concrete.

  • isEmpty(t type) -> bool

Returns true in the case where a abstract type is the union of no concrete types, and so contains no values.

  • isEnum(t type) -> bool

Returns true if the type is an enum, and an error if it's abstract.

  • isStruct(t type) -> bool

Returns true if the type is a struct, and an error if it's abstract.

  • fieldLabels(t type) -> list

If the type is a struct, this returns a list of the labels of its fields, and an error otherwise.

  • fieldTypes(t type) -> list

If the type is a struct, this returns a list of the types of its fields, and an error otherwise.

  • name(t type) -> string

Returns the name of the type, e.g. int, Varchar{8}.

  • operator(t type) -> string

Returns the operator of the type if it's concrete.

  • parameterTypes(t type) -> list

Returns the types of the type parameters (or an empty list if not parameterized) for clone or struct types, otherwise returns an error.

  • parameterValues(t type) -> list

Returns the values of the type parameters (or an empty list if not parameterized) for clone or struct types, otherwise returns an error.

  • parent(t type) -> type

Returns the parent of the type if it's a clone, and an error otherwise.

  • subtypes(t type) -> set

Returns a set of all the concrete types that are subtypes of the given type.

Clone this wiki locally