Skip to content

Commands Cheat Sheet

Karl Ostmo edited this page Nov 2, 2024 · 22 revisions

Note, this page is auto-generated by

cabal run swarm:swarm-docs -O0 -- cheatsheet --commands

If you notice this page is out-of-date, instead of editing it, you can help by regenerating the tables using the most up-to-date swarm executable and pasting the result here!

Commands

Syntax Type Capability Description
noop Cmd Unit Do nothing.
wait Int -> Cmd Unit wait Wait for a number of time steps.
selfdestruct Cmd Unit selfdestruct Self-destruct a robot.
move Cmd Unit move Move forward one step.
backup Cmd Unit backup Move backward one step.
volume Int -> Cmd (Unit + Int) volume Measure enclosed volume.
path (Unit + Int) -> ((Int * Int) + Text) -> Cmd (Unit + (Dir * Int)) path Obtain shortest path to the destination.
push Cmd Unit push Push an entity forward one step.
stride Int -> Cmd Unit stride Move forward multiple steps.
turn Dir -> Cmd Unit turn Turn in some direction.
grab Cmd Text grab Grab an item from the current location.
harvest Cmd Text harvest Harvest an item from the current location.
sow Text -> Cmd Unit sow Plant a seed at current location
ignite Dir -> Cmd Unit ignite Ignite a combustible item in the specified direction.
place Text -> Cmd Unit place Place an item at the current location.
ping Actor -> Cmd (Unit + (Int * Int)) ping Obtain the relative location of another robot.
give Actor -> Text -> Cmd Unit give Give an item to another actor nearby.
equip Text -> Cmd Unit equip Equip a device on oneself.
unequip Text -> Cmd Unit unequip Unequip an equipped device, returning to inventory.
make Text -> Cmd Unit make Make an item using a recipe.
has Text -> Cmd Bool Sense whether the robot has a given item in its inventory.
equipped Text -> Cmd Bool Sense whether the robot has a specific device equipped.
count Text -> Cmd Int count Get the count of a given item in a robot's inventory.
drill Dir -> Cmd (Unit + Text) drill Drill through an entity.
use Text -> Dir -> Cmd (Unit + Text) Use one entity upon another.
build ∀ a. {Cmd a} -> Cmd Actor build Construct a new robot.
salvage Cmd Unit salvage Deconstruct an old robot.
reprogram ∀ a. Actor -> {Cmd a} -> Cmd Unit reprogram Reprogram another robot with a new command.
say Text -> Cmd Unit Emit a message.
listen Cmd Text listen Listen for a message from other actors.
log Text -> Cmd Unit log Log the string in the robot's logger.
view Actor -> Cmd Unit View the given actor.
appear Text -> (Unit + Text) -> Cmd Unit appear Set how the robot is displayed.
create Text -> Cmd Unit god Create an item out of thin air.
halt Actor -> Cmd Unit halt Tell a robot to halt.
time Cmd Int time Get the current time.
scout Dir -> Cmd Bool scout Detect whether a robot is within line-of-sight in a direction.
whereami Cmd (Int * Int) whereami Get the current x and y coordinates.
locateme Cmd (Text * (Int * Int)) locateme Get the current subworld and x, y coordinates.
waypoint Text -> Int -> Cmd (Int * (Int * Int)) waypoint Get the x, y coordinates of a named waypoint, by index
structure Text -> Int -> Cmd (Unit + (Int * (Int * Int))) structure Get the x, y coordinates of the southwest corner of a constructed structure, by name and index
floorplan Text -> Cmd (Int * Int) floorplan Get the dimensions of a structure template
hastag Text -> Text -> Cmd Bool hastag Check whether the given entity has the given tag
tagmembers Text -> Int -> Cmd (Int * Text) tagmembers Get the entities labeled by a tag.
detect Text -> ((Int * Int) * (Int * Int)) -> Cmd (Unit + (Int * Int)) detect Detect an entity within a rectangle.
resonate Text -> ((Int * Int) * (Int * Int)) -> Cmd Int resonate Count specific entities within a rectangle.
density ((Int * Int) * (Int * Int)) -> Cmd Int density Count all entities within a rectangle.
sniff Text -> Cmd Int sniff Determine distance to entity.
chirp Text -> Cmd Dir chirp Determine direction to entity.
watch Dir -> Cmd Unit watch Interrupt wait upon location changes.
surveil (Int * Int) -> Cmd Unit god Interrupt wait upon (remote) location changes.
heading Cmd Dir heading Get the current heading.
blocked Cmd Bool blocked See if the robot can move forward.
scan Dir -> Cmd (Unit + Text) scan Scan a nearby location for entities.
upload Actor -> Cmd Unit upload Upload a robot's known entities and log to another robot.
ishere Text -> Cmd Bool ishere See if a specific entity is in the current location.
isempty Cmd Bool isempty Check if the current location is empty.
meet Cmd (Unit + Actor) meet Get a reference to a nearby actor, if there is one.
meetall Cmd (rec l. Unit + (Actor * l)) meetall Return a list of all the nearby actors.
whoami Cmd Text whoami Get the robot's display name.
setname Text -> Cmd Unit Set the robot's display name.
random Int -> Cmd Int random Get a uniformly random integer.
run Text -> Cmd Unit Run a program loaded from a file.
return ∀ a. a -> Cmd a Make the value a result in cmd.
try ∀ a. {Cmd a} -> {Cmd a} -> Cmd a try Execute a command, catching errors.
swap Text -> Cmd Text swap Swap placed entity with one in inventory.
atomic ∀ a. Cmd a -> Cmd a atomic Execute a block of commands atomically.
instant ∀ a. Cmd a -> Cmd a god Execute a block of commands instantly.
installkeyhandler Text -> (Key -> Cmd Unit) -> Cmd Unit installkeyhandler Install a keyboard input handler.
teleport Actor -> (Int * Int) -> Cmd Unit teleport Teleport a robot to the given location.
warp Actor -> (Text * (Int * Int)) -> Cmd Unit warp Relocate a robot to the given cosmic location.
as ∀ a. Actor -> {Cmd a} -> Cmd a god Hypothetically run a command as if you were another robot.
robotnamed Text -> Cmd Actor god Find an actor by name.
robotnumbered Int -> Cmd Actor god Find an actor by number.
knows Text -> Cmd Bool Check if the robot knows about an entity.

Builtin functions

These functions are evaluated immediately once they have enough arguments.

Syntax Type Capability Description
self Actor self Get a reference to the current robot.
parent Actor Get a reference to the robot's parent.
base Actor Get a reference to the base.
if ∀ a. Bool -> {a} -> {a} -> a if If-Then-Else function.
inl ∀ a b. a -> (a + b) sum Put the value into the left component of a sum type.
inr ∀ a b. b -> (a + b) sum Put the value into the right component of a sum type.
case ∀ a b c. (a + b) -> (a -> c) -> (b -> c) -> c sum Evaluate one of the given functions on a value of sum type.
fst ∀ a b. (a * b) -> a prod Get the first value of a pair.
snd ∀ a b. (a * b) -> b prod Get the second value of a pair.
force ∀ a. {a} -> a Force the evaluation of a delayed value.
undefined ∀ a. a A value of any type, that is evaluated as error.
fail ∀ a. Text -> a A value of any type, that is evaluated as error with message.
not Bool -> Bool not Negate the boolean value.
format ∀ a. a -> Text format Turn an arbitrary value into a string.
chars Text -> Int chars Counts the number of characters in the text.
split Int -> Text -> (Text * Text) split Split the text into two at given position.
charat Int -> Text -> Int charat Get the character at a given index.
tochar Int -> Text tochar Create a singleton text value from the given character code.
key Text -> Key key Create a key value from a text description.

Operators

Syntax Type Capability Description
- Int -> Int neg Negate the given integer value.
== ∀ a. a -> a -> Bool == Check that the left value is equal to the right one.
!= ∀ a. a -> a -> Bool != Check that the left value is not equal to the right one.
< ∀ a. a -> a -> Bool < Check that the left value is lesser than the right one.
> ∀ a. a -> a -> Bool > Check that the left value is greater than the right one.
<= ∀ a. a -> a -> Bool <= Check that the left value is lesser or equal to the right one.
>= ∀ a. a -> a -> Bool >= Check that the left value is greater or equal to the right one.
|| Bool -> Bool -> Bool || Logical or (true if either value is true).
&& Bool -> Bool -> Bool && Logical and (true if both values are true).
+ Int -> Int -> Int + Add the given integer values.
- Int -> Int -> Int - Subtract the given integer values.
* Int -> Int -> Int * Multiply the given integer values.
/ Int -> Int -> Int / Divide the left integer value by the right one, rounding down.
^ Int -> Int -> Int ^ Raise the left integer value to the power of the right one.
++ Text -> Text -> Text ++ Concatenate the given strings.
$ ∀ a b. (a -> b) -> a -> b Apply the function on the left to the value on the right.

Detailed descriptions

Noop

  • syntax: noop
  • type: Cmd Unit

Do nothing.

This is different than Wait in that it does not take up a time step. It is useful for commands like if, which requires you to provide both branches. Usually it is automatically inserted where needed, so you do not have to worry about it.

Wait

  • syntax: wait
  • type: Int -> Cmd Unit
  • required capabilities: wait

Wait for a number of time steps.

Selfdestruct

  • syntax: selfdestruct
  • type: Cmd Unit
  • required capabilities: selfdestruct

Self-destruct a robot.

Useful to not clutter the world. This destroys the robot's inventory, so consider salvage as an alternative.

Move

  • syntax: move
  • type: Cmd Unit
  • required capabilities: move

Move forward one step.

Backup

  • syntax: backup
  • type: Cmd Unit
  • required capabilities: backup

Move backward one step.

Volume

  • syntax: volume
  • type: Int -> Cmd (Unit + Int)
  • required capabilities: volume

Measure enclosed volume.

Specify the max volume to check for. Returns either the measured volume bounded by "unwalkable" cells, or unit if the search exceeds the limit. There is also an implicit hard-coded maximum of 4096

Path

  • syntax: path
  • type: (Unit + Int) -> ((Int * Int) + Text) -> Cmd (Unit + (Dir * Int))
  • required capabilities: path

Obtain shortest path to the destination.

Optionally supply a distance limit as the first argument. Supply either a location (inL) or an entity (inR) as the second argument. If a path exists, returns the immediate direction to proceed along and the remaining distance.

Push

  • syntax: push
  • type: Cmd Unit
  • required capabilities: push

Push an entity forward one step.

Both entity and robot moves forward one step. Destination must not contain an entity.

Stride

  • syntax: stride
  • type: Int -> Cmd Unit
  • required capabilities: stride

Move forward multiple steps.

Has a max range of 64 units.

Turn

  • syntax: turn
  • type: Dir -> Cmd Unit
  • required capabilities: turn

Turn in some direction.

Grab

  • syntax: grab
  • type: Cmd Text
  • required capabilities: grab

Grab an item from the current location.

Harvest

  • syntax: harvest
  • type: Cmd Text
  • required capabilities: harvest

Harvest an item from the current location.

Leaves behind a growing seed if the harvested item is growable. Otherwise it works exactly like grab.

Sow

  • syntax: sow
  • type: Text -> Cmd Unit
  • required capabilities: sow

Plant a seed at current location

The entity this matures into may be something else.

Ignite

  • syntax: ignite
  • type: Dir -> Cmd Unit
  • required capabilities: ignite

Ignite a combustible item in the specified direction.

Combustion persists for a random duration and may spread.

Place

  • syntax: place
  • type: Text -> Cmd Unit
  • required capabilities: place

Place an item at the current location.

The current location has to be empty for this to work.

Ping

  • syntax: ping
  • type: Actor -> Cmd (Unit + (Int * Int))
  • required capabilities: ping

Obtain the relative location of another robot.

The other robot must be within transmission range, accounting for antennas installed on either end, and the invoking robot must be oriented in a cardinal direction. The location (x, y) is given relative to one's current orientation: Positive x value is to the right, negative left. Likewise, positive y value is forward, negative back.

Give

  • syntax: give
  • type: Actor -> Text -> Cmd Unit
  • required capabilities: give

Give an item to another actor nearby.

Equip

  • syntax: equip
  • type: Text -> Cmd Unit
  • required capabilities: equip

Equip a device on oneself.

Unequip

  • syntax: unequip
  • type: Text -> Cmd Unit
  • required capabilities: unequip

Unequip an equipped device, returning to inventory.

Make

  • syntax: make
  • type: Text -> Cmd Unit
  • required capabilities: make

Make an item using a recipe.

Has

  • syntax: has
  • type: Text -> Cmd Bool

Sense whether the robot has a given item in its inventory.

Equipped

  • syntax: equipped
  • type: Text -> Cmd Bool

Sense whether the robot has a specific device equipped.

Count

  • syntax: count
  • type: Text -> Cmd Int
  • required capabilities: count

Get the count of a given item in a robot's inventory.

Drill

  • syntax: drill
  • type: Dir -> Cmd (Unit + Text)
  • required capabilities: drill

Drill through an entity.

Usually you want to drill forward when exploring to clear out obstacles. When you have found a source to drill, you can stand on it and drill down. See what recipes with drill you have available. The drill command may return the name of an entity added to your inventory.

Use

  • syntax: use
  • type: Text -> Dir -> Cmd (Unit + Text)

Use one entity upon another.

Which entities you can use with others depends on the available recipes. The object being used must be a 'required' entity in a recipe.

Build

  • syntax: build
  • type: ∀ a. {Cmd a} -> Cmd Actor
  • required capabilities: build

Construct a new robot.

You can specify a command for the robot to execute. If the command requires devices they will be taken from your inventory and equipped on the new robot.

Salvage

  • syntax: salvage
  • type: Cmd Unit
  • required capabilities: salvage

Deconstruct an old robot.

Salvaging a robot will give you its inventory, equipped devices and log.

Reprogram

  • syntax: reprogram
  • type: ∀ a. Actor -> {Cmd a} -> Cmd Unit
  • required capabilities: reprogram

Reprogram another robot with a new command.

The other robot has to be nearby and idle.

Say

  • syntax: say
  • type: Text -> Cmd Unit

Emit a message.

The message will be in the robot's log (if it has one) and the global log. You can view the message that would be picked by listen from the global log in the messages panel, along with your own messages and logs. This means that to see messages from other robots you have to be able to listen for them, so once you have a listening device equipped messages will be added to your log. In creative mode, there is of course no such limitation.

Listen

  • syntax: listen
  • type: Cmd Text
  • required capabilities: listen

Listen for a message from other actors.

It will take the first message said by the closest actor. You do not need to actively listen for the message to be logged though, that is done automatically once you have a listening device equipped. Note that you can see the messages either in your logger device or the message panel.

Log

  • syntax: log
  • type: Text -> Cmd Unit
  • required capabilities: log

Log the string in the robot's logger.

View

  • syntax: view
  • type: Actor -> Cmd Unit

View the given actor.

This will recenter the map on the target robot and allow its inventory and logs to be inspected.

Appear

  • syntax: appear
  • type: Text -> (Unit + Text) -> Cmd Unit
  • required capabilities: appear

Set how the robot is displayed.

You can either specify one character or five (one for each direction: down, north, east, south, west). The default is "X^>v<". The second argument is for optionally setting a display attribute (i.e. color).

Create

  • syntax: create
  • type: Text -> Cmd Unit
  • required capabilities: god

Create an item out of thin air.

Only available in creative mode.

Halt

  • syntax: halt
  • type: Actor -> Cmd Unit
  • required capabilities: halt

Tell a robot to halt.

Time

  • syntax: time
  • type: Cmd Int
  • required capabilities: time

Get the current time.

Scout

  • syntax: scout
  • type: Dir -> Cmd Bool
  • required capabilities: scout

Detect whether a robot is within line-of-sight in a direction.

Perception is blocked by 'Opaque' entities. Has a max range of 64 units.

Whereami

  • syntax: whereami
  • type: Cmd (Int * Int)
  • required capabilities: whereami

Get the current x and y coordinates.

LocateMe

  • syntax: locateme
  • type: Cmd (Text * (Int * Int))
  • required capabilities: locateme

Get the current subworld and x, y coordinates.

Waypoint

  • syntax: waypoint
  • type: Text -> Int -> Cmd (Int * (Int * Int))
  • required capabilities: waypoint

Get the x, y coordinates of a named waypoint, by index

Return only the waypoints in the same subworld as the calling robot. Since waypoint names can have plural multiplicity, returns a tuple of (count, (x, y)). The supplied index will be wrapped automatically, modulo the waypoint count. A robot can use the count to know whether they have iterated over the full waypoint circuit.

Structure

  • syntax: structure
  • type: Text -> Int -> Cmd (Unit + (Int * (Int * Int)))
  • required capabilities: structure

Get the x, y coordinates of the southwest corner of a constructed structure, by name and index

The outermost type of the return value indicates whether any structure of such name exists. Since structures can have multiple occurrences, returns a tuple of (count, (x, y)). The supplied index will be wrapped automatically, modulo the structure count. A robot can use the count to know whether they have iterated over the full structure list.

Floorplan

  • syntax: floorplan
  • type: Text -> Cmd (Int * Int)
  • required capabilities: floorplan

Get the dimensions of a structure template

Returns a tuple of (width, height) for the structure of the requested name. Yields an error if the supplied string is not the name of a structure.

HasTag

  • syntax: hastag
  • type: Text -> Text -> Cmd Bool
  • required capabilities: hastag

Check whether the given entity has the given tag

Returns true if the first argument is an entity that is labeled by the tag in the second argument. Yields an error if the first argument is not a valid entity.

TagMembers

  • syntax: tagmembers
  • type: Text -> Int -> Cmd (Int * Text)
  • required capabilities: tagmembers

Get the entities labeled by a tag.

Returns a tuple of (member count, entity). The supplied index will be wrapped automatically, modulo the member count. A robot can use the count to know whether they have iterated over the full list. Item order is determined by definition sequence in the scenario file.

Detect

  • syntax: detect
  • type: Text -> ((Int * Int) * (Int * Int)) -> Cmd (Unit + (Int * Int))
  • required capabilities: detect

Detect an entity within a rectangle.

Locate the closest instance of a given entity within the rectangle specified by opposite corners, relative to the current location.

Resonate

  • syntax: resonate
  • type: Text -> ((Int * Int) * (Int * Int)) -> Cmd Int
  • required capabilities: resonate

Count specific entities within a rectangle.

Applies a strong magnetic field over a given area and stimulates the matter within, generating a non-directional radio signal. A receiver tuned to the resonant frequency of the target entity is able to measure its quantity. Counts the entities within the rectangle specified by opposite corners, relative to the current location.

Density

  • syntax: density
  • type: ((Int * Int) * (Int * Int)) -> Cmd Int
  • required capabilities: density

Count all entities within a rectangle.

Applies a strong magnetic field over a given area and stimulates the matter within, generating a non-directional radio signal. A receiver measured the signal intensity to measure the quantity. Counts the entities within the rectangle specified by opposite corners, relative to the current location.

Sniff

  • syntax: sniff
  • type: Text -> Cmd Int
  • required capabilities: sniff

Determine distance to entity.

Measures concentration of airborne particles to infer distance to a certain kind of entity. If none is detected, returns (-1). Has a max range of 256 units.

Chirp

  • syntax: chirp
  • type: Text -> Cmd Dir
  • required capabilities: chirp

Determine direction to entity.

Uses a directional sonic emitter and microphone tuned to the acoustic signature of a specific entity to determine its direction. Returns 'down' if out of range or the direction is indeterminate. Provides absolute directions if "compass" equipped, relative directions otherwise. Has a max range of 256 units.

Watch

  • syntax: watch
  • type: Dir -> Cmd Unit
  • required capabilities: watch

Interrupt wait upon location changes.

Place seismic detectors to alert upon entity changes to the specified location. Supply a direction, as with the scan command, to specify a nearby location. Can be invoked more than once until the next wait command, at which time the only the registered locations that are currently nearby are preserved. Any change to entities at the monitored locations will cause the robot to wake up before the wait timeout.

Surveil

  • syntax: surveil
  • type: (Int * Int) -> Cmd Unit
  • required capabilities: god

Interrupt wait upon (remote) location changes.

Like watch, but instantaneous and with no restriction on distance. Supply absolute coordinates.

Heading

  • syntax: heading
  • type: Cmd Dir
  • required capabilities: heading

Get the current heading.

Blocked

  • syntax: blocked
  • type: Cmd Bool
  • required capabilities: blocked

See if the robot can move forward.

Scan

  • syntax: scan
  • type: Dir -> Cmd (Unit + Text)
  • required capabilities: scan

Scan a nearby location for entities.

Adds the entity (not actor) to your inventory with count 0 if there is any. If you can use sum types, you can also inspect the result directly.

Upload

  • syntax: upload
  • type: Actor -> Cmd Unit
  • required capabilities: upload

Upload a robot's known entities and log to another robot.

Ishere

  • syntax: ishere
  • type: Text -> Cmd Bool
  • required capabilities: ishere

See if a specific entity is in the current location.

Isempty

  • syntax: isempty
  • type: Cmd Bool
  • required capabilities: isempty

Check if the current location is empty.

Detects whether or not the current location contains an entity. Does not detect robots or other actors.

Meet

  • syntax: meet
  • type: Cmd (Unit + Actor)
  • required capabilities: meet

Get a reference to a nearby actor, if there is one.

MeetAll

  • syntax: meetall
  • type: Cmd (rec l. Unit + (Actor * l))
  • required capabilities: meetall

Return a list of all the nearby actors.

Whoami

  • syntax: whoami
  • type: Cmd Text
  • required capabilities: whoami

Get the robot's display name.

Setname

  • syntax: setname
  • type: Text -> Cmd Unit

Set the robot's display name.

Random

  • syntax: random
  • type: Int -> Cmd Int
  • required capabilities: random

Get a uniformly random integer.

The random integer will be chosen from the range 0 to n-1, exclusive of the argument.

Run

  • syntax: run
  • type: Text -> Cmd Unit

Run a program loaded from a file.

Return

  • syntax: return
  • type: ∀ a. a -> Cmd a

Make the value a result in cmd.

Try

  • syntax: try
  • type: ∀ a. {Cmd a} -> {Cmd a} -> Cmd a
  • required capabilities: try

Execute a command, catching errors.

Swap

  • syntax: swap
  • type: Text -> Cmd Text
  • required capabilities: swap

Swap placed entity with one in inventory.

This essentially works like atomic grab and place. Use this to avoid race conditions where more robots grab, scan or place in one location.

Atomic

  • syntax: atomic
  • type: ∀ a. Cmd a -> Cmd a
  • required capabilities: atomic

Execute a block of commands atomically.

When executing atomic c, a robot will not be interrupted, that is, no other robots will execute any commands while the robot is executing @c@.

Instant

  • syntax: instant
  • type: ∀ a. Cmd a -> Cmd a
  • required capabilities: god

Execute a block of commands instantly.

Like atomic, but with no restriction on program size.

InstallKeyHandler

  • syntax: installkeyhandler
  • type: Text -> (Key -> Cmd Unit) -> Cmd Unit
  • required capabilities: installkeyhandler

Install a keyboard input handler.

The first argument is a hint line that will be displayed when the input handler is active. The second argument is a function to handle keyboard inputs.

Teleport

  • syntax: teleport
  • type: Actor -> (Int * Int) -> Cmd Unit
  • required capabilities: teleport

Teleport a robot to the given location.

Warp

  • syntax: warp
  • type: Actor -> (Text * (Int * Int)) -> Cmd Unit
  • required capabilities: warp

Relocate a robot to the given cosmic location.

As

  • syntax: as
  • type: ∀ a. Actor -> {Cmd a} -> Cmd a
  • required capabilities: god

Hypothetically run a command as if you were another robot.

RobotNamed

  • syntax: robotnamed
  • type: Text -> Cmd Actor
  • required capabilities: god

Find an actor by name.

RobotNumbered

  • syntax: robotnumbered
  • type: Int -> Cmd Actor
  • required capabilities: god

Find an actor by number.

Knows

  • syntax: knows
  • type: Text -> Cmd Bool

Check if the robot knows about an entity.

Self

  • syntax: self
  • type: Actor
  • required capabilities: self

Get a reference to the current robot.

Parent

  • syntax: parent
  • type: Actor

Get a reference to the robot's parent.

Base

  • syntax: base
  • type: Actor

Get a reference to the base.

If

  • syntax: if
  • type: ∀ a. Bool -> {a} -> {a} -> a
  • required capabilities: if

If-Then-Else function.

If the bool predicate is true then evaluate the first expression, otherwise the second.

Inl

  • syntax: inl
  • type: ∀ a b. a -> (a + b)
  • required capabilities: sum

Put the value into the left component of a sum type.

Inr

  • syntax: inr
  • type: ∀ a b. b -> (a + b)
  • required capabilities: sum

Put the value into the right component of a sum type.

Case

  • syntax: case
  • type: ∀ a b c. (a + b) -> (a -> c) -> (b -> c) -> c
  • required capabilities: sum

Evaluate one of the given functions on a value of sum type.

Fst

  • syntax: fst
  • type: ∀ a b. (a * b) -> a
  • required capabilities: prod

Get the first value of a pair.

Snd

  • syntax: snd
  • type: ∀ a b. (a * b) -> b
  • required capabilities: prod

Get the second value of a pair.

Force

  • syntax: force
  • type: ∀ a. {a} -> a

Force the evaluation of a delayed value.

Undefined

  • syntax: undefined
  • type: ∀ a. a

A value of any type, that is evaluated as error.

Fail

  • syntax: fail
  • type: ∀ a. Text -> a

A value of any type, that is evaluated as error with message.

Not

  • syntax: not
  • type: Bool -> Bool
  • required capabilities: not

Negate the boolean value.

Format

  • syntax: format
  • type: ∀ a. a -> Text
  • required capabilities: format

Turn an arbitrary value into a string.

Chars

  • syntax: chars
  • type: Text -> Int
  • required capabilities: chars

Counts the number of characters in the text.

Split

  • syntax: split
  • type: Int -> Text -> (Text * Text)
  • required capabilities: split

Split the text into two at given position.

To be more specific, the following holds for all text values s1 and s2: (s1,s2) == split (chars s1) (s1 ++ s2) So split can be used to undo concatenation if you know the length of the original string.

CharAt

  • syntax: charat
  • type: Int -> Text -> Int
  • required capabilities: charat

Get the character at a given index.

Gets the character (as an int representing a Unicode codepoint) at a specific index in a text value. Valid indices are 0 through chars t - 1. Throws an exception if given an out-of-bounds index.

ToChar

  • syntax: tochar
  • type: Int -> Text
  • required capabilities: tochar

Create a singleton text value from the given character code.

That is, chars (toChar c) == 1 and charAt 0 (toChar c) == c.

Key

  • syntax: key
  • type: Text -> Key
  • required capabilities: key

Create a key value from a text description.

The key description can optionally start with modifiers like 'C-', 'M-', 'A-', or 'S-', followed by either a regular key, or a special key name like 'Down' or 'End' For example, 'M-C-x', 'Down', or 'S-4'. Which key combinations are actually possible to type may vary by keyboard and terminal program.

Neg

  • syntax: -
  • type: Int -> Int
  • required capabilities: neg

Negate the given integer value.

Eq

  • syntax: ==
  • type: ∀ a. a -> a -> Bool
  • required capabilities: ==

Check that the left value is equal to the right one.

Neq

  • syntax: !=
  • type: ∀ a. a -> a -> Bool
  • required capabilities: !=

Check that the left value is not equal to the right one.

Lt

  • syntax: <
  • type: ∀ a. a -> a -> Bool
  • required capabilities: <

Check that the left value is lesser than the right one.

Gt

  • syntax: >
  • type: ∀ a. a -> a -> Bool
  • required capabilities: >

Check that the left value is greater than the right one.

Leq

  • syntax: <=
  • type: ∀ a. a -> a -> Bool
  • required capabilities: <=

Check that the left value is lesser or equal to the right one.

Geq

  • syntax: >=
  • type: ∀ a. a -> a -> Bool
  • required capabilities: >=

Check that the left value is greater or equal to the right one.

Or

  • syntax: ||
  • type: Bool -> Bool -> Bool
  • required capabilities: ||

Logical or (true if either value is true).

And

  • syntax: &&
  • type: Bool -> Bool -> Bool
  • required capabilities: &&

Logical and (true if both values are true).

Add

  • syntax: +
  • type: Int -> Int -> Int
  • required capabilities: +

Add the given integer values.

Sub

  • syntax: -
  • type: Int -> Int -> Int
  • required capabilities: -

Subtract the given integer values.

Mul

  • syntax: *
  • type: Int -> Int -> Int
  • required capabilities: *

Multiply the given integer values.

Div

  • syntax: /
  • type: Int -> Int -> Int
  • required capabilities: /

Divide the left integer value by the right one, rounding down.

Exp

  • syntax: ^
  • type: Int -> Int -> Int
  • required capabilities: ^

Raise the left integer value to the power of the right one.

Concat

  • syntax: ++
  • type: Text -> Text -> Text
  • required capabilities: ++

Concatenate the given strings.

AppF

  • syntax: $
  • type: ∀ a b. (a -> b) -> a -> b

Apply the function on the left to the value on the right.

This operator is useful to avoid nesting parentheses. For exaple: f $ g $ h x = f (g (h x))