Skip to content
Playground(another site)

Operators & built-ins

OperatorArityOperandsResultNotes
+ - * /binaryInt (or Float; or Decimal for + - *)Intarithmetic; no % (a % is the error bynk.parse.no_remainder_operator, which points at Int.rem and Int.mod, below); / on Int truncates and on Float divides, but is not defined on Decimal (below)
-unaryInt (or Decimal)Intnegation
== !=binarysame equality-supporting type (compared structurally)Boolnon-associative
< <= > >=binarytwo operands of the same Ord typeBoolcomparison; IEEE on Float (NaN < x is false)
&& ||binaryBoolBoollogical
!unaryBoolBoollogical not
impliesbinaryBoolBoollogical implication (P implies Q ≡ !P || Q, directional); lowest precedence; in invariant predicates (invariants)
isbinarysum value + patternBoolvariant test, may bind (guide)
?postfixResultunwraps Okpropagates Err; only in a Result-returning fn
<-bindEffect[T]Tsequences an effect in a let

There is no string concatenation operator: + requires numeric operands.

Lowest to highest:

  1. expect (in expression position)
  2. implies (lowest-precedence operator; predicate language)
  3. ||
  4. &&
  5. == != is (non-associative — no chaining)
  6. < <= > >=
  7. + -
  8. * /
  9. unary - !
  10. postfix: ?, .field, .method(…), calls

So expect x == 1 parses as expect (x == 1), and a + b * c as a + (b * c).

Bynk has no % operator. Writing one is the error bynk.parse.no_remainder_operator, which names the two methods that do the work (Int.rem and Int.mod, ADR 0660):

WriteSign of the resultSame as
a.rem(b)the dividend’s ((-7).rem(2) is -1)C, Java and JavaScript’s %
a.mod(b)the divisor’s ((-7).mod(2) is 1)Python’s %

When both operands are plain names or integer literals, the error offers a quick fix (never applied automatically, since only Int has rem) that rewrites n % 2 to n.rem(2); check that you wanted the dividend’s sign, and change it to .mod for a cyclic index. Any other operand, such as (a + b) % size, gets the explanation without a fix.

Decimal is exact base-10 arithmetic. Its operand and result rules:

ExpressionResultNotes
Decimal + Decimal, Decimal - DecimalDecimalexact; the result has the larger of the two scales
Decimal * DecimalDecimalexact; the result’s scale is the sum of the two
-DecimalDecimalexact
Decimal / Decimalrejectedbynk.types.decimal_division_unscaled: a quotient has no exact answer, so write a.div(b, scale, RoundingMode.<mode>)
Decimal == Decimal, <, <=, >, >=Boolby numeric value, so 1.20d == 1.2d
Decimal with Int or Float, in any operatorrejectedbynk.types.no_numeric_coercion; use Decimal.fromInt(n) or a decimal literal

See Decimal for rounding, parsing and the wire form.

Duration (a span) and Instant (an absolute point in time) compose through a fixed operator surface; every other numeric mix between them — or with Int — is a bynk.types.no_numeric_coercion error.

ExpressionResultNotes
Duration ± DurationDurationsubtraction is unclamped (may go negative)
Duration * Int / Int * DurationDurationscalar scaling
Duration vs Duration (< <= > >=)Boolcomparison
Instant ± DurationInstantadvance / retreat
Instant - InstantDurationthe span between
Instant vs Instant (< <= > >=)Boolchronological ordering

Instant is orderable (so sortBy/min/max key on it) but not numeric (sum/average reject it). Timestamp math goes through Instant — Clock.now() + 5.minutes is Instant + Duration. The earlier Int + Duration -> Int clock-math coercion was withdrawn at v0.90; mixing Instant with Int now errors. Convert explicitly with d.toMillis() / Duration.millis(n) and t.toEpochMillis() / Instant.fromEpochMillis(n), and to RFC 3339 text through t.toIso() / Instant.fromIso(s). See types.

FormMeaning
if c { … } else { … }conditional expression; branches share a type
match e { … }exhaustive pattern match (types)
let x = e / let x: T = ebinding; let x <- e binds an effect
T.of(…)refined/opaque checked construction; T.unsafe(…) is opaque-only (refined types)
name := ewrite a store Cell field; committed at handler end (agents)

Int, Float, String, Bool, Duration, Instant, the unit (), and the generics Result[T, E], Option[T], Effect[T], HttpResult[T], Stream[T], Query[T]. See the type system reference.