Declare a trait method
Usage
trait_method(
params,
description = "",
default_impl = NULL,
stochastic = FALSE,
dispatch = NULL,
return_type = NULL,
rules = list()
)Arguments
- params
The method's parameters, from
params(); the first is the value the method dispatches on.- description
Character: What the method does.
- default_impl
Optional function: The method's default implementation, used for a type whose impl does not define the method.
- stochastic
Logical: The method draws random numbers.
- dispatch
Optional Character: The arguments the method dispatches on, by name, at most three and none of them
...; the first argument by default. Every method of a trait dispatches on the same number of arguments, and an impl names a type for any of them (impl()).- return_type
Optional: The type of the value that every impl's method returns, an
r8_field_type, an R8 type, or"Self", the type of the first dispatched argument. An impl may declare a type that fits it (impl_method()). A replacement method returns a value of its argument's type and declares none.- rules
A
rule(), or a list of rules, over the typed parameters, which every call satisfies once each argument satisfies its type.
Examples
trait_method(params(spec, x, y), description = "Trains a model.")#> <r8 trait method>
#> Trains a model.
#> spec
#> x
#> y#> <r8 trait method>
#> x
#> y
#> ...
#> dispatches on x, ytrait_method(
params(spec, x, verbosity = arg_integer(min = 0L, default = 1L)),
return_type = type_double()
)#> <r8 trait method>
#> spec
#> x
#> verbosity: integer [0, Inf) = 1L
#> returns double