Top-level configuration binding. Must be named config.
| Field | Type | Description |
|---|---|---|
| name | String | Display title |
| description | String | Subtitle text |
| package_name | String | Must match computation package |
| function_name | String | Entry function to call |
| inputs | List[(String, InputEntry)] | Named input controls |
| outputs | List[(String, OutputEntry)] | Named output displays |
| assumptions | List[AssumptionConfig] | What-if toggles (or []) |
| snippet_max_lines | Int | Why snippet limit (0 = disabled) |
Each returns an InputSpec[a]; the value type is determined by the constructor.
| Helper | Description |
|---|---|
bind_discrete | Polymorphic in value type; declares the input as Discrete (drives bar charts in Stage 2). |
bind_continuous | Int-only; declares the input as Continuous (drives line charts). |
Both helpers yield an InputHandle[a]. Read the typed default with value(handle).
| Helper | X-axis policy |
|---|---|
currency_output / number_output / percent_output | XAxisDisallowed (scalar only) |
currency_output_chartable / number_output_chartable / percent_output_chartable | Caller supplies an XAxisMode |
Pinned/Default/Optional take typed InputHandle[Int] references and a ChartRange(samples, min_override, max_override).
| Field | Type | Description |
|---|---|---|
| name | String | Toggle label |
| description | String | Help text |
| variants | List[(String, String)] | (label, function_suffix) pairs |
def config_builder() -> SimBuilder:
x_h <- bind_continuous("x", "X", int_slider(0, 100, 1, 50))
result <- outputs(calculate(value(x_h)))
match result:
case Result(y):
[
currency_output("y", "Result", y, True)
]
config = sim(
"My Sim", "Description",
"MyPackage", "calculate",
config_builder(),
[], 0
)
Each h <- bind_continuous(...) line is sugar for bind_continuous(..., h -> rest), so the next bind sees h in scope without nesting lambdas. The same pattern works for bind_discrete and outputs.
from Yichus/Simulation import ( int_slider, int_number_input, int_dropdown, bool_checkbox, bool_dropdown, string_dropdown, SimBuilder, value, bind_discrete, bind_continuous, outputs, number_output, currency_output, percent_output, number_output_chartable, currency_output_chartable, percent_output_chartable, sim )
package MyPackage from Bosatsu/Predef import Int, String, Bool, List from Bosatsu/Numeric import Double, from_Int
Each file starts with package Name. Use from Pkg import ... to bring names into scope.
| Type | Notes |
|---|---|
| Int | Arbitrary-precision integer |
| String | Text value |
| Bool | True or False |
| List[A] | Linked list, e.g. [1, 2, 3] |
| (A, B) | Tuple, e.g. ("key", 42) |
| Double | Floating point (from Bosatsu/Numeric) |
struct Point(x: Int, y: Int) p = Point(3, 4) # Access fields via pattern matching
def add(a: Int, b: Int) -> Int: a.add(b) def greet(name: String) -> String: "Hello, ".concat(name)
Functions use indentation for body. Type annotations are required on parameters and return type.
match point:
case Point(x, y):
x.add(y)
Exhaustive matching is required. Use _ for wildcard.
enum Color: Red, Green, Blue match c: case Red: "red" case Green: "green" case Blue: "blue"
Constructors are bare names imported directly.
def calc(x: Int) -> Int: doubled = x.times(2) offset = doubled.add(10) offset
Bindings are name = expr. The last expression is the return value.
| Function | Signature |
|---|---|
| add | Int -> Int -> Int |
| sub | Int -> Int -> Int |
| times | Int -> Int -> Int |
| div | Int -> Int -> Int |
| mod_Int | Int -> Int -> Int |
| eq_Int | Int -> Int -> Bool |
| cmp_Int | Int -> Int -> Comparison |
| int_to_String | Int -> String |
| concat_String | String -> String -> String |
from Bosatsu/Numeric import ( Double, from_Int, add_Double, sub_Double, mul_Double, div_Double )
| Function | Signature |
|---|---|
| from_Int | Int -> Double |
| add_Double | Double -> Double -> Double |
| sub_Double | Double -> Double -> Double |
| mul_Double | Double -> Double -> Double |
| div_Double | Double -> Double -> Double |
All values are immutable. No loops -- use recursion or foldLeft.
Integer math only by default. Use from_Int to convert to Double for fractional arithmetic.