Inferno Programming Language – Function Reference

Comments #

Inferno is a hybrid scripting language created by Plow Technologies, that brings powerful realtime scripting capabilities to applications that use it. Think of inferno as excel scripting for real-time data.

Listed below is Inferno’s syntax rules for various operations:

Commenting Syntax #

Inferno’s comment types include single-line and multi-line commenting:

'//' for single-line comments
'/…/' for multi-line comments

Numeric Literals #

Inferno’s numeric types include integer literals and floating point literals.
Integer literals represent fixed positive or negative integer values that are a nonfractional whole number like 300, 43, 777, -234 etc. (with in the integer range).
Floating point literals represent positive or negative fractional values with decimals like 56.43, 2.66, 1204.99 etc.

Integer and Floating Point Syntax Examples #

3        // integer literal
-3       // negative integer literal
3.0      // floating-point literal
-3.0     // negative floating-point literal

Arithmetic Syntax #

Inferno supports basic arithmetic operations on numeric types meaning that it can be used to perform mathematical calculations such as addition, subtraction, multiplication, and division on numbers. In addition to these basic operations, Inferno also supports more mathematical functions such as logarithms and exponentials. These functions can be useful for more complex calculations.
Here are some examples of basic arithmetic operations and syntax examples in Inferno:

 

OperationOperatorSyntax ExampleResult
Add‘+’3 + 47
Subtract‘-‘3.0 – 21.0
Divide‘/’3.0 / 21.5
Multiply‘*’3.14* recip 3.141.0
Power‘**’1.4** 2.51.9843134832984438
Power (exp,ln)‘exp’ ‘ln’exp (ln 1)1.0
Logs‘log’ ‘logBase’logBase 10 1002.0
Logs (exp,ln)‘exp’ ‘lnln (exp 1)1.0
Square Root‘sqrt’sqrt 1.4251.1941939201359381m
Negation‘let x =’let x = 1425 in -x-1425
Absolute Val‘abs’abs (-14.25)14.25
Modulus‘%’-3 % 52

  #

Testing #

You can use the assert statement to write simple tests in your code.

assert will be taken out when the code is ran outside of the testing enviornment.

Example:

// user: what does the negation function look like in inferno?
// - : {requires negate on 'a} ⇒ 'a → 'a
// Negation (unary) on int, double, or timeDiff
let negationInt = - (-3)
in assert (negationInt == 3) 
in let negationDouble = - (- 3.0)
in assert (negationDouble == 3.0) 
in let negationTimeDiff = - (Time.hours (-3))
in assert (negationTimeDiff == Time.hours 3)
in negationInt

 

Array Syntax #

A variety of expressions can be used to build complex programs with Array:

ExpressionFunctionExpression ExampleResult
Array.sumCalculates the sum of an array, after filtering out the None values.Array.sum (Array.keepSomes [Some 3.0, None, Some 4.0])0.7
Array.findFirstSomeFinds the first element in an array that is not None.Array.findFirstSome [None, Some 3.0, None, Some 4.0]A value that represents the found element.
Array.findLastSomeFinds the last element in an array that is not None.Array.findLastSome [None, Some 3.0, None, Some 4.0]A value that represents the found element.
Array.findFirstAndLastSomeFinds both the first and last element in an array that is not None.Array.findFirstAndLastSome [None, Some 3.0, None, Some 4.0]A tuple of two values, each represents the found element

Fetching Data From OnPing #

ExpressionFunctionExpression ExampleResult
valueAtFind the value of an input stream at a given time.
: {implicit resolution : resolution} ⇒ series of ‘a → time → option of ‘a
valueAt input0 ?now0.7
latestValueFinds the latest value from an input stream.latestValue input00.8
latestValueBeforeFinds the latest value from an input stream before some given time.latestValueBefore ?now input00.8

Data Formatting #

ExpressionFunctionExpression ExampleResult
truncateToCut off decimals after n valuestruncateTo 0 3.1234
truncateTo 1 3.1234
truncateTo 2 3.1234
3
3.1
3.12

Option Syntax #

A variety of expressions can be used to build complex programs with Option:

ExpressionFunctionExpression ExampleResult
Option.mapMaps the given function to the value of the option, if it exists.Option.map (fun x -> x + 2) (Some 4.0)A value that represents the result of the mapping operation
fromOptionExtracts the value of an option, or returns the default if option is None.fromOption 0 (Some 4.0)A value of the options or the default value, depending on the value.
Operator “?”Returns the value of the option if it exists, or default if option is None.(Some 4.0) ? 0A value of the option or the default value, depending on the option
Option.reduceApplies the given binary function to elements of option. Returns the resultOption.reduce (fun d -> d + 2) 0.0 (Some 4.0)A value that represents the result of the reduction operation.

Bitwise Operations #

Bitwise Operation Expression ExampleResultFunction
0x5 && 0x91Performs a bitwise AND operation on two values.
0x5 XOR 0x63Performs a bitwise XOR operation on two values.
!(toWord16 0x1)65534Performs a bitwise NOT operation on a value.
testBit (setBit 0x0 3) 3vTrueSets a bit in a value and then checks if it is set.
shift 0x1 38Performs a bit shift operation on a value.
fromWord #false0Converts a Boolean value to an integer.

Word Conversion #

Word Conversion Expression ExampleResultFunction
toWord16 #true1Converts a Boolean value to a 16-bit unsigned integer.
toWord16 (toWord64 77)77Converts a 64-bit unsigned integer to a 16-bit unsigned integer.
toWord16 (toWord64 (2**17 + 2))22Converts a large 64-bit unsigned integer to a 16-bit unsigned integer.
toWord32 (toWord64 77)77Converts a 64-bit unsigned integer to a 32-bit unsigned integer
toWord32 (toWord64 (2**33 + 5))5Converts a large 64-bit unsigned integer to a 32-bit unsigned integer.
toWord64 (toWord16 (2**62 + 1))1Converts a large 16-bit unsigned integer to a 64-bit unsigned integer.

Word Size Conversion #

Word Size Conversion Expression ExampleResultFunction
fromWord (toWord64 (2**62))4611686018427387904Converts a large unsigned integer to a signed integer.
fromWord (toWord32 (262 + 231))2147483648Converts a 64-bit unsigned integer to a 16-bit unsigned integer.
fromWord (toWord16 (231 + 23))8Converts a large unsigned integer to a signed integer.

Data Retrieval

Word Size Conversion Expression ExampleResultFunction
valueAt t inputSome valRetrieve an approximate value for a data stream at a given time.
latestValueBefore t inputSome valRetrieve an approximate value for a data stream at a given time.
latestInput inputSome valRetrieve the first value found, which occurred before the default ?now

Automated Function Reference

Module Base (needs no prefix) #

! : forall 'a . {requires bitlike on 'a} ⇒ 'a → 'a

Complements (switches 0s and 1s) all bits in the argument

- : forall 'a . {requires negate on 'a} ⇒ 'a → 'a

Negation (unary) on int, double, or timeDiff

None : forall 'a . option of 'a

Optional type, representing a value which may be undefined. None indicates no value is present and Some v holds a value v To test whether an optional o holds some value, use match ... with and pattern match on o: ~~~ match o with { | Some v -> // use v here | None -> // handle the case where o is None } ~~~

Some : forall 'a . 'a → option of 'a

Optional type, representing a value which may be undefined. None indicates no value is present and Some v holds a value v To test whether an optional o holds some value, use match ... with and pattern match on o: ~~~ match o with { | Some v -> // use v here | None -> // handle the case where o is None } ~~~

abs : forall 'a . {requires abs on 'a} ⇒ 'a → 'a

Absolute value (sometimes written |x|) on int, double, or timeDiff

arcCos : double → double

Inverse cosine (trigonometric function) of a double

arcSin : double → double

Inverse sine (trigonometric function) of a double

arcTan : double → double

Inverse tan (trigonometric function) of a double

ceiling : forall 'a . {requires roundable on 'a} ⇒ 'a → int

Ceiling function (rounds up to nearest integer)

clearBit : forall 'a . {requires bitlike on 'a} ⇒ 'a → int → 'a

Clears the bit at the provided offset (i.e., sets it to 0)

complementBit : forall 'a . {requires bitlike on 'a} ⇒ 'a → int → 'a

Switches the bit at the provided offset (0 to 1 or vice versa)

cos : double → double

Cosine (trigonometric function), on double

cosh : double → double

Hyperbolic cosine (trigonometric function) of a double

doubleToInt : double → int

Convert double to int

exp : double → double

Exponential function

floor : forall 'a . {requires roundable on 'a} ⇒ 'a → int

Floor function (rounds down to nearest integer)

fromBCD : word64 → option of word64

Decode a BCD-encoded word64

fromOption : forall 'a . 'a → option of 'a → 'a

The fromOption function unwraps an optional value, if given a default value to fall back on in case the value of the optional is None. ~~~inferno fromOption “hi” (Some “hello”) == “hello” fromOption “hi” None == “hi” ~~~

fromWord : forall 'a . {requires fromWord on 'a} ⇒ 'a → int

Convert a word to an int

fst : forall 'a 'b . ('a, 'b) → 'a

Gets the first component of a tuple: fst (x, y) == x

id : forall 'a . 'a → 'a

The identity function

intToDouble : int → double

Convert int to double

latestValue : forall 'a . {implicit now : time} ⇒ series of 'a → option of 'a

Returns the latest value of the parameter, if one exists.

latestValueAndTime : forall 'a . {implicit now : time} ⇒ series of 'a → option of ('a, time)

Returns the latest value of the parameter (and the corresponding timestamp), if one exists.

latestValueAndTimeBefore : forall 'a . time → series of 'a → option of ('a, time)

Returns the latest value of the parameter (and the corresponding timestamp) before the given time, if one exists.

latestValueBefore : forall 'a . time → series of 'a → option of 'a

Returns the latest value of the parameter before the given time, if one exists.

limit : double → double → double → double

limit l u x = min l (max x u) limits x to be between l and u

ln : double → double

Natural logarithm

log : double → double

Logarithm with base 10

logBase : double → double → double

Logarithm with base b

max : forall 'a . {requires order on 'a} ⇒ 'a → 'a → 'a

Maximum function on int, double, word16/32/64, time and timeDiff

min : forall 'a . {requires order on 'a} ⇒ 'a → 'a → 'a

Minimum function on int, double, word16/32/64, time and timeDiff

pi : double

Pi (3.14159... :: double), the constant

random : () → double

A (pseudo)random double

recip : double → double

Reciprocal fraction

resolutionToInt : resolution → int

round : forall 'a . {requires roundable on 'a} ⇒ 'a → int

round x returns the nearest integer to x (the even integer if x is equidistant between two integers)

roundTo : int → double → double

roundTo d x rounds x to d decimal places

setBit : forall 'a . {requires bitlike on 'a} ⇒ 'a → int → 'a

Sets the bit at the provided offset to 1

shift : forall 'a . {requires bitlike on 'a} ⇒ 'a → int → 'a

shift x i shifts x left by i bits if i is positive, or right by -i bits otherwise. Right shifts perform sign extension on signed number types (i.e. they fill the top bits with 1 if x is negative and with 0 otherwise)

sin : double → double

Sine (trigonometric function) of a double

sinh : double → double

Hyperbolic sine (trigonometric function) of a double

snd : forall 'a 'b . ('a, 'b) → 'b

Gets the second component of a tuple: snd (x, y) == y

sqrt : double → double

Square root

tan : double → double

Tan (trigonometric function), on double

tanh : double → double

Hyperbolic tangent (trigonometric function) of a double

testBit : forall 'a . {requires bitlike on 'a} ⇒ 'a → int → bool{#false,#true}

Checks if the bit at the provided offset is set

toBCD : word64 → word64

Encode a BCD-encoded word64

toResolution : int → resolution

toWord16 : forall 'a . {requires toWord16 on 'a} ⇒ 'a → word16

Convert an int or another word to a word16, dropping bits if necessary

toWord32 : forall 'a . {requires toWord32 on 'a} ⇒ 'a → word32

Convert an int or another word to a word32, dropping bits if necessary

toWord64 : forall 'a . {requires toWord64 on 'a} ⇒ 'a → word64

Convert an int or another word to a word64

truncate : forall 'a . {requires roundable on 'a} ⇒ 'a → int

truncate x returns the integer nearest x between zero and x

truncateTo : int → double → double

truncateTo d x truncates x to d decimal places

valueAt : forall 'a . {implicit resolution : resolution} ⇒ series of 'a → time → option of 'a

Returns the value of the parameter in the chunk containing the given time, if it exists. For example, if resolution is 128 (thus chunks are 0-127, 128-255, 256-383, …), and the parameter p has values: ~~~ V: 1.0 | | 3.0 | T: 0 … 120 … 127 128 … 255 256 … 300 … 383 384 … ~~~ then: ~~~inferno open Time in valueAt p (toTime (seconds 128)) == Some 1.0 valueAt p (toTime (seconds 129)) == None valueAt p (toTime (seconds 380)) == Some 3.0 ~~~

valueAtOrAdjacent : forall 'a . {implicit resolution : resolution} ⇒ series of 'a → time → option of 'a

Returns the value of the parameter in the chunk containing the given time, if it exists, or in the closest adjacent chunk (previous or next chunk), if it exists. For example, if resolution is 128 (thus chunks are 0-127, 128-255, 256-383, …), and the parameter p has values: ~~~ V: 1.0 | | 3.0 |4.0 T: 0 … 120 … 127 128 … 255 256 … 300 … 383 384 … ~~~ then: ~~~inferno open Time in valueAtOrAdjacent p (toTime (seconds 380)) == Some 3.0 // value from current chunk valueAtOrAdjacent p (toTime (seconds 130)) == Some 1.0 // value from previous chunk valueAtOrAdjacent p (toTime (seconds 200)) == Some 3.0 // value from next chunk valueAtOrAdjacent p (toTime (seconds 1024)) == None ~~~

valuesBetween : forall 'a . {implicit resolution : resolution} ⇒ series of 'a → time → time → array of ('a, time)

Returns all values between two times, using the implicit resolution. If the resolution is set to 1, this returns all the events (actual values, not approximations) in the given time window.

zip : forall 'a 'b . array of 'a → array of 'b → array of ('a, 'b)

Zip two arrays into a array of tuples/pairs. If one input array is shorter than the other, excess elements of the longer array are discarded. zip [1, 2] ['a', 'b'] == [(1,'a'),(2,'b')]

(!!) : forall 'a . array of 'a → int → 'a

Array indexing: an infix operator to get the ith element of an array. Throws a RuntimeError if i is out of bounds.

(!=) : forall 'a . 'a → 'a → bool{#false,#true}

The (not) equals function works on any value of the same type. Always returns #true for functions

(!?) : forall 'a . array of 'a → int → option of 'a

Safe array indexing: an infix operator to get the ith element of an array. Returns None if i is out of bounds.

(%) : int → int → int

(&&) : forall 'a . {requires bitlike on 'a} ⇒ 'a → 'a → 'a

Bitwise AND

(*) : forall 'a 'b 'c . {requires multiplication on 'a 'b 'c} ⇒ 'a → 'b → 'c

Multiplication on int, double

(**) : forall 'a . {requires power on 'a} ⇒ 'a → 'a → 'a

x ** y raises x to the power of y, where the arguments are int or double

(+) : forall 'a 'b 'c . {requires addition on 'a 'b 'c} ⇒ 'a → 'b → 'c

Addition on int, double, word16/32/64, time and timeDiff

(-) : forall 'a 'b 'c . {requires subtraction on 'a 'b 'c} ⇒ 'a → 'b → 'c

Subtraction on int, double, word16/32/64, time and timeDiff

(..) : int → int → array of int

(/) : forall 'a 'b 'c . {requires division on 'a 'b 'c} ⇒ 'a → 'b → 'c

Division on int, double

(<) : forall 'a . {requires order on 'a} ⇒ 'a → 'a → bool{#false,#true}

Ordering on int, double, word16/32/64, time and timeDiff

(<<) : forall 'a 'b 'c . ('a → 'b) → ('c → 'a) → 'c → 'b

Function composition. (f << g) x == f (g x)

(<=) : forall 'a . {requires order on 'a} ⇒ 'a → 'a → bool{#false,#true}

Ordering on int, double, word16/32/64, time and timeDiff

(==) : forall 'a . 'a → 'a → bool{#false,#true}

The equality function works on any value of the same type. Always returns #false for functions

(>) : forall 'a . {requires order on 'a} ⇒ 'a → 'a → bool{#false,#true}

Ordering on int, double, word16/32/64, time and timeDiff

(>=) : forall 'a . {requires order on 'a} ⇒ 'a → 'a → bool{#false,#true}

Ordering on int, double, word16/32/64, time and timeDiff

(?) : forall 'a . option of 'a → 'a → 'a

The ? function unwraps an optional value, if given a default value to fall back on in case the value of the optional is None. ~~~inferno (Some “hello”) ? “hi” == “hello” None ? “hi” == “hi” ~~~

(XOR) : forall 'a . {requires bitlike on 'a} ⇒ 'a → 'a → 'a

Bitwise XOR

(|>) : forall 'a 'b . 'a → ('a → 'b) → 'b

The pipe operator. x |> f |> g == g (f x)

(||) : forall 'a . {requires bitlike on 'a} ⇒ 'a → 'a → 'a

Bitwise OR

Module Array #

argmax : forall 'a . {requires order on 'a} ⇒ array of 'a → option of int

The index of the maximum value in an array, or None if empty

argmin : forall 'a . {requires order on 'a} ⇒ array of 'a → option of int

The index of the minimum value in an array, or None if empty

argsort : forall 'a . {requires order on 'a} ⇒ array of 'a → array of int

Returns the indices that would sort an array

average : forall 'a . {requires numeric on 'a} ⇒ array of 'a → option of double

The average of the values in an array, or None if empty

findFirstAndLastSome : forall 'a . array of (option of 'a) → option of ('a, 'a)

findFirstSome : forall 'a . array of (option of 'a) → option of 'a

findLastSome : forall 'a . array of (option of 'a) → option of 'a

get : forall 'a . array of 'a → int → 'a

Array indexing: gets the ith element of an array. Throws a RuntimeError if i is out of bounds.

getOpt : forall 'a . array of 'a → int → option of 'a

Safe array indexing: gets the ith element of an array. Returns None if i is out of bounds.

keepSomes : forall 'a . array of (option of 'a) → array of 'a

Array.keepSomes discards any None values in an array and unwaps all Somes. ~~~inferno Array.keepSomes [None, Some “hello”, None, Some “world”] = [“hello”, “world”] ~~~

length : forall 'a . array of 'a → int

magnitude : forall 'a . {requires numeric on 'a} ⇒ array of 'a → option of double

Returns the Euclidean norm of an array, or None if empty

map : forall 'a 'b . ('a → 'b) → array of 'a → array of 'b

The Array.map function takes a function f and an array of elements and applies f to each one

maximum : forall 'a . {requires order on 'a} ⇒ array of 'a → option of 'a

The maximum value in an array, or None if empty

median : forall 'a . {requires numeric on 'a} ⇒ array of 'a → option of double

Return the median of the values in an array, or None if empty

minimum : forall 'a . {requires order on 'a} ⇒ array of 'a → option of 'a

The minimum value in an array, or None if empty

norm : forall 'a . {requires numeric on 'a} ⇒ array of 'a → option of double

Returns the Euclidean norm of an array, or None if empty

range : int → int → array of int

The Array.range function takes two int arguments n and m and produces an array [n,...,m]. If m > n, the empty array is returned.

reduce : forall 'a 'b . ('a → 'b → 'a) → 'a → array of 'b → 'a

reduceRight : forall 'a 'b . ('a → 'b → 'b) → 'b → array of 'a → 'b

singleton : forall 'a . 'a → array of 'a

This function can be used to create an array with a single element: ~~~inferno singleton 2 ~~~

sum : forall 'a 'b . {requires addition on 'b 'a 'b ,requires rep on 'b ,requires zero on 'b} ⇒ array of 'a → 'b

Array.sum computes the sum of elements in an array. The elements can be of type int/double/word.

zero : forall 'a . {requires rep on 'a,requires zero on 'a} ⇒ 'a

Module Option #

join : forall 'a . option of (option of 'a) → option of 'a

Option.join removes the outer “layer” of a nesteed option. (By definition, Option.join == Option.reduce id None). ~~~inferno Option.join None == None Option.join (Some None) == None Option.join (Some (Some a)) == Some a ~~~

map : forall 'a 'b . ('a → 'b) → option of 'a → option of 'b

Option.map f ma applies f to the value inside ma, namely if ma is Some a, it will return Some (f a).

mergeTuple : forall 'a 'b . (option of 'a, option of 'b) → option of ('a, 'b)

Given a tuple (Some x , Some y), Option.mergeTuple`` returnsSome (x , y)otherwise it returnsNone`.

reduce : forall 'a 'b . ('a → 'b) → 'b → option of 'a → 'b

Option.reduce f o d unwraps an optional value o and applies f to it, if o contains a Some value. Otherwise it returns the default value d. ~~~inferno Option.reduce (fun str -> ${str} there!) “hi” (Some “hello”) == “hello there!” Option.reduce (fun str -> ${str} there!) “hi” None == “hi” ~~~

singleton : forall 'a . 'a → option of 'a

Module Text #

append : text → text → text

length : text → int

splitAt : int → text → (text, text)

strip : text → text

Module Time #

day : time → time

Rounds down to the start of the nearest day

days : int → timeDiff

daysBefore : time → int → time

formatTime : time → text → text

Format time to string

hour : time → time

Rounds down to the start of the nearest hour

hours : int → timeDiff

hoursBefore : time → int → time

intervalEvery : timeDiff → time → time → array of time

minutes : int → timeDiff

minutesBefore : time → int → time

month : time → time

Rounds down to the start of the nearest month

monthsBefore : time → int → time

Subtracts the given number of months, with days past the last day of the month clipped to the last day. For instance, 1 month before 2005-03-30 is 2005-02-28.

seconds : int → timeDiff

secondsBefore : time → int → time

timeToInt : time → int

Convert time to int (returned as seconds)

toTime : timeDiff → time

weeks : int → timeDiff

weeksBefore : time → int → time

year : time → time

Rounds down to the start of the nearest year

yearsBefore : time → int → time

Subtracts the given number of years, with days past the last day of the month clipped to the last day. For instance, 2 years before 2006-02-29 is 2004-02-28.

Type Classes #

abs

  • int
  • double
  • timeDiff

addition

  • int int int
  • int double double
  • double int double
  • double double double
  • word16 word16 word16
  • word16 word32 word32
  • word16 word64 word64
  • word32 word16 word32
  • word32 word32 word32
  • word32 word64 word64
  • word64 word16 word64
  • word64 word32 word64
  • word64 word64 word64
  • time timeDiff time
  • timeDiff time time
  • timeDiff timeDiff timeDiff

bitlike

  • word16
  • word32
  • word64
  • bool{#false,#true}

division

  • int int int
  • int double double
  • double int double
  • double double double

fromWord

  • word16
  • word32
  • word64
  • bool{#false,#true}

multiplication

  • int int int
  • int double double
  • int timeDiff timeDiff
  • double int double
  • double double double
  • timeDiff int timeDiff

negate

  • int
  • double
  • timeDiff

order

  • int
  • double
  • time
  • timeDiff

power

  • int
  • double

roundable

  • int
  • double

subtraction

  • int int int
  • int double double
  • double int double
  • double double double
  • word16 word16 word16
  • word32 word32 word32
  • word64 word64 word64
  • time timeDiff time
  • timeDiff timeDiff timeDiff

toWord16

  • int
  • word16
  • word32
  • word64
  • bool{#false,#true}

toWord32

  • int
  • word16
  • word32
  • word64
  • bool{#false,#true}

toWord64

  • int
  • word16
  • word32
  • word64
  • bool{#false,#true}

zero

  • int
  • double
  • word16
  • word32
  • word64
  • timeDiff

Powered by BetterDocs