concepts.dsl.function_domain.FunctionDomain#
- class FunctionDomain[source]#
 Bases:
DSLDomainBaseA basic domain definition that contains a collection of types, constants, and functions.
Methods
define([implementation])A context manager that defines the types, constants, and functions in the domain.
define_const(dtype, value)Define a constant with the given type and value.
define_function(function[, implementation])Define a function in the domain.
define_overloaded_function(name, overloads)Define a function with multiple overloads.
define_type(t)Define a type in the domain.
deserialize(dictionary)Deserialize a program from a dictionary.
Format the summary of the domain.
get_function(name)Get the function with the given name.
has_function(name)Check whether the domain has a function with the given name.
lam(lambda_expression[, name, typing_cues])Parse a lambda expression into a Function instance.
overload(function)Overload a function.
Print the summary of the domain.
serialize(program)Serialize a program into a dictionary.
Attributes
alias of
ObjectType|ValueType|FunctionTypeThe name of the domain.
The types defined in the domain, as a dictionary from type names to types.
The functions defined in the domain, as a dictionary from function names to functions.
The constants defined in the domain, as a dictionary from the name to the
Valueobjects.- __init__(name=None)[source]#
 Initialize the domain.
- Parameters:
 name (str | None) – the name of the domain. If not specified, the name of the class will be used.
- __new__(**kwargs)#
 
- define(implementation=True)[source]#
 A context manager that defines the types, constants, and functions in the domain.
Usage:
with domain.define(): A = domain.define_type('A', ...) B = domain.define_type('B', ...) # Definition of constants. Equivalent to `domain.define_const(domain.types['A'], 'a')`. a: A b: B # Definition of functions. def f(a: A, b: B) -> A: pass # Definition of overloaded functions. @domain.overload def g(a: A, b: B) -> A: pass @domain.overload def g(b: B, a: A) -> B: pass
Note that the definition for constants is only allowed when the code is executed at the global scope.
- define_const(dtype, value)#
 Define a constant with the given type and value.
- Parameters:
 dtype (ObjectType | ValueType) – the type of the constant.
value (str) – the value of the constant. The value should be a string that is the name of the constant.
- define_function(function, implementation=True)#
 Define a function in the domain.
- define_overloaded_function(name, overloads, implementation=True)[source]#
 Define a function with multiple overloads.
- define_type(t)#
 Define a type in the domain.
- Parameters:
 t (ObjectType | ValueType) – the type to be defined.
- Returns:
 the type that is defined.
- Return type:
 
- deserialize(dictionary)[source]#
 Deserialize a program from a dictionary.
- get_function(name)#
 Get the function with the given name.
- has_function(name)#
 Check whether the domain has a function with the given name.
- lam(lambda_expression, name='__lambda__', typing_cues=None)[source]#
 Parse a lambda expression into a Function instance.
- Parameters:
 lambda_expression (Callable) – the lambda expression.
name (str) – the name of the function.
typing_cues (Dict[str, str | TypeBase] | None) – the typing cues for the function. It should be a dictionary that maps the argument names to the types.
type (If you want to specify the return)
'return'. (use the key)
- Returns:
 The parsed
Functioninstance.- Return type:
 
- serialize(program)[source]#
 Serialize a program into a dictionary.
- Parameters:
 program (FunctionApplicationExpression | Value) – the program to be serialized.
- Returns:
 the serialized program.
- Return type:
 
- AllowedTypes#
 alias of
ObjectType|ValueType|FunctionType
- constants: Dict[str, Value]#
 The constants defined in the domain, as a dictionary from the name to the
Valueobjects.
- functions: Dict[str, Function]#
 The functions defined in the domain, as a dictionary from function names to functions.
- types: Dict[str, ObjectType | ValueType]#
 The types defined in the domain, as a dictionary from type names to types.