Yichus Playground Back to demos
Ready
Output
Edit the Bosatsu source and click Run to see your simulation
Reference

SimConfig

Top-level configuration binding. Must be named config.

FieldTypeDescription
nameStringDisplay title
descriptionStringSubtitle text
package_nameStringMust match computation package
function_nameStringEntry function to call
inputsList[(String, InputEntry)]Named input controls
outputsList[(String, OutputEntry)]Named output displays
assumptionsList[AssumptionConfig]What-if toggles (or [])
snippet_max_linesIntWhy snippet limit (0 = disabled)

Smart input constructors

int_slider int_number_input int_dropdown bool_checkbox bool_dropdown string_dropdown

Each returns an InputSpec[a]; the value type is determined by the constructor.

Bind helpers

HelperDescription
bind_discretePolymorphic in value type; declares the input as Discrete (drives bar charts in Stage 2).
bind_continuousInt-only; declares the input as Continuous (drives line charts).

Both helpers yield an InputHandle[a]. Read the typed default with value(handle).

OutputFormat (enum)

Currency Percent Number

Output helpers

HelperX-axis policy
currency_output / number_output / percent_outputXAxisDisallowed (scalar only)
currency_output_chartable / number_output_chartable / percent_output_chartableCaller supplies an XAxisMode

XAxisMode (enum)

XAxisDisallowed XAxisPinned XAxisDefault XAxisOptional

Pinned/Default/Optional take typed InputHandle[Int] references and a ChartRange(samples, min_override, max_override).

AssumptionConfig

FieldTypeDescription
nameStringToggle label
descriptionStringHelp text
variantsList[(String, String)](label, function_suffix) pairs

Quick Example

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.

Import Line

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
)

Packages & Imports

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.

Types

TypeNotes
IntArbitrary-precision integer
StringText value
BoolTrue or False
List[A]Linked list, e.g. [1, 2, 3]
(A, B)Tuple, e.g. ("key", 42)
DoubleFloating point (from Bosatsu/Numeric)

Structs

struct Point(x: Int, y: Int)

p = Point(3, 4)
# Access fields via pattern matching

Functions

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.

Pattern Matching

match point:
  case Point(x, y):
    x.add(y)

Exhaustive matching is required. Use _ for wildcard.

Enums

enum Color: Red, Green, Blue

match c:
  case Red: "red"
  case Green: "green"
  case Blue: "blue"

Constructors are bare names imported directly.

Let Bindings

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.

Common Predef Functions

FunctionSignature
addInt -> Int -> Int
subInt -> Int -> Int
timesInt -> Int -> Int
divInt -> Int -> Int
mod_IntInt -> Int -> Int
eq_IntInt -> Int -> Bool
cmp_IntInt -> Int -> Comparison
int_to_StringInt -> String
concat_StringString -> String -> String

Bosatsu/Numeric (Double)

from Bosatsu/Numeric import (
  Double, from_Int,
  add_Double, sub_Double,
  mul_Double, div_Double
)
FunctionSignature
from_IntInt -> Double
add_DoubleDouble -> Double -> Double
sub_DoubleDouble -> Double -> Double
mul_DoubleDouble -> Double -> Double
div_DoubleDouble -> Double -> Double

Tips

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.

Full language guide →