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, InputConfig)]Named input controls
outputsList[(String, OutputConfig)]Named output displays
assumptionsList[AssumptionConfig]What-if toggles (or [])
sweepsList[SweepConfig]Parameter sweep charts (or [])
snippet_max_linesIntWhy snippet limit (0 = disabled)

Widget (enum)

Slider NumberInput

InputConfig

FieldTypeDescription
labelStringDisplay label
default_valueIntInitial value
min_valueIntMinimum bound
max_valueIntMaximum bound
stepIntStep increment
widgetWidgetSlider or NumberInput

OutputFormat (enum)

Currency Percent Number

OutputConfig

FieldTypeDescription
labelStringDisplay label
formatOutputFormatHow to format the value
primaryBoolTrue = highlighted output

ChartType (enum)

Line Area Bar

SweepConfig

FieldTypeDescription
input_paramStringInput name to sweep
min_valueIntSweep start
max_valueIntSweep end
stepsIntNumber of data points
output_paramStringOutput name to plot
chart_typeChartTypeLine, Area, or Bar

AssumptionConfig

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

Quick Example

config = SimConfig(
  "My Sim", "Description",
  "MyPackage", "calculate",
  [("x", InputConfig("X", 50, 0, 100, 1, Slider))],
  [("y", OutputConfig("Result", Currency, True))],
  [], [], 0
)

Import Line

from Yichus/Simulation import (
  InputConfig, OutputConfig,
  AssumptionConfig, SweepConfig, SimConfig,
  Slider, NumberInput,
  Currency, Percent, Number,
  Line, Area, Bar
)

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 →