March Docs

Prelude

March Standard Library Prelude

Everything in this module is auto-imported into every March program. These are the most commonly needed functions and types.

Sections:

  1. Diverging (panic, todo, unreachable)
  2. Option helpers
  3. Result helpers
  4. List basics
  5. Combinators (identity, compose, flip, const)
  6. String helpers

Functions

fnpanicpanic(msg : String) : a#

Terminates the program with a runtime error. Used for violated invariants — bugs, not expected failures. Propagates to the enclosing actor boundary.

fntodotodo(msg : String) : a#

Marks code as not yet implemented. Typechecks as any type so you can sketch a program top-down. Never valid in production.

fnunreachableunreachable() : a#

Asserts that a code path is unreachable.

fnunwrapunwrap(opt : Option(a)) : a#

Extracts the value from Some(x), panicking if None.

fnunwrap_orunwrap_or(opt : Option(a), default : a) : a#

Returns the contained value, or default if None.

fnheadhead(xs : List(a)) : a#

Returns the first element of the list. Panics if empty.

fntailtail(xs : List(a)) : List(a)#

Returns all but the first element. Panics if empty.

fnis_nilis_nil(xs : List(a)) : Bool#

Returns true if the list is empty.

fnlengthlength(xs : List(a)) : Int#

Returns the number of elements in the list.

fnreversereverse(xs : List(a)) : List(a)#

Reverses a list.

fnfold_leftfold_left(acc : b, xs : List(a), f : b -> a -> b) : b#

Left fold over a list.

fnfilterfilter(xs : List(a), pred : a -> Bool) : List(a)#

Returns only the elements satisfying pred.

fnmapmap(xs : List(a), f : a -> b) : List(b)#

Applies f to every element of the list.

fnidentityidentity(x : a) : a#

The identity function — returns its argument unchanged.

fncomposecompose(f : b -> c, g : a -> b) : a -> c#

Function composition: compose(f, g)(x) = f(g(x)).

fnflipflip(f : a -> b -> c) : b -> a -> c#

Flips the order of arguments: flip(f)(b, a) = f(a, b).

fnconstconst(x : a) : b -> a#

Returns a function that always returns x, ignoring its argument.

fndebugdebug(x : a) : Unit#

Prints a value using its Show representation, with a trailing newline.

fninspectinspect(x : a) : String#

Converts any value to its string representation.