Inferno supports two types of comments, //
for single-line comments and /* ... */ for multi-line comments.
Numeric Literals
Inferno supports both integer and floating-point literals. The type of the literal is inferred by the context in which it appears.
3 // integer literal
-3 // negative integer literal
3.0 // floating-point literal
-3.0 // negative floating-point literal
Inferno supports basic arithmetic operations on numeric types.
Addition is done using the +
operator.
3 + 4 // evaluates to 7
Subtraction is done using the -
operator.
3.0 - 2 // evaluates to 1.0
Division is done using the /
operator.
3.0 / 2 // evaluates to 1.5
Multiplication is done using the *
operator.
3.14 * recip 3.14 // evaluates to 1.0
Inferno supports exponentiation using the **
operator.
The exp
function calculates the exponential function and the ln
function calculates the natural logarithm.
Examples:
14 ** 5 // evaluates to 537824
1.4 ** 2.5 // evaluates to 1.9843134832984438
exp 0 // evaluates to 1.0
exp (ln 1) // evaluates to 1.0
Inferno supports logarithmic functions. log
calculates the logarithm in base 10, logBase
calculates the logarithm with a given base, and ln
calculates the natural logarithm.
Examples:
log 10 // evaluates to 1.0
logBase 10 100 // evaluates to 2.0
ln (exp 1) // evaluates to 1.0
Inferno provides the sqrt
function to calculate the square root of a number.
Examples:
sqrt 1.425 // evaluates to 1.1941939201359381
sqrt (-1.425) // evaluates to NaN
Inferno provides the unary -
operator for negation.
Examples:
let x = 1425 in -x // evaluates to -1425
let x = 1.425 in -x // evaluates to -1.425
Inferno provides the abs function for calculating the absolute value of a number.
Examples:
abs 1425 // evaluates to 1425
abs (-1425) // evaluates to 1425
abs 14.25 // evaluates to 14.25
abs (-14.25) // evaluates to 14.25
Inferno provides the % operator for calculating the modulus of two integers.
1425 % 5 // evaluates to 0
1426 % 5 // evaluates to 1
-3 % 5 // evaluates to 2
Inferno provides the floor and ceiling functions for rounding to the nearest integer in the appropriate direction. The round function rounds to the nearest integer, while roundTo and
The language supports a variety of expressions that can be used to build complex programs with Array. Here is an example of an expression:
Array.sum (Array.keepSomes [Some 3.0, None, Some 4.0])
This expression calculates the sum of an array after filtering out the None values. The expected result of this expression is 7.0, which is a double.
Here are a few examples of expressions that can be evaluated using the language:
Array.sum (Array.keepSomes [Some 3.0, None, Some 4.0])
This expression calculates the sum of an array after filtering out the None values. The expected result of this expression is 7.0, which is a double.
h## Array.findFirstSome
Array.findFirstSome [None, Some 3.0, None, Some 4.0]
This expression finds the first element in an array that is not None. The expected result of this expression is a value that represents the found element.
Array.findLastSome [None, Some 3.0, None, Some 4.0]
This expression finds the last element in an array that is not None. The expected result of this expression is a value that represents the found element.
Array.findFirstAndLastSome [None, Some 3.0, None, Some 4.0]
This expression finds both the first and last element in an array that is not None. The expected result of this expression is a tuple of two values, where each value represents the found element.
Option.map (fun x -> x + 2) (Some 4.0)
This expression maps the given function to the value of the option, if it exists. The expected result of this expression is a value that represents the result of the mapping operation.
fromOption 0 (Some 4.0)
This expression extracts the value of an option, or returns the default value if the option is None. The expected result of this expression is the value of the option or the default value, depending on the value of the option.
(Some 4.0) ? 0
This expression returns the value of the option if it exists, or the given default value if the option is None. The expected result of this expression is the value of the option or the default value, depending on the value of the option.
Option.reduce (fun d -> d + 2) 0.0 (Some 4.0)
This expression applies the given binary function to the elements of the option and returns the result. The expected result of this expression is a value that represents the result of the reduction operation.
0x5 && 0x9
This expression performs a bitwise AND operation on two values. The expected result of this expression is 1, which is the result of the bitwise operation.
0x5 XOR 0x6
This expression performs a bitwise XOR operation on two values. The expected result of this expression is 3, which is the result of the bitwise operation.
!(toWord16 0x1)
This expression performs a bitwise NOT operation on a value. The expected result of this expression is 65534, which is the result of the bitwise operation. Bit Manipulations
testBit (setBit 0x0 3) 3
This expression sets a bit in a value and then checks if it is set. The expected result of this expression is vTrue, indicating that the bit is set.
shift 0x1 3
This expression performs a bit shift operation on a value. The expected result of this expression is 8, which is the result of the bit shift operation.
fromWord #false
This expression converts a Boolean value to an integer. The expected result of this expression is 0.
toWord16 #true
This expression converts a Boolean value to a 16-bit unsigned integer. The expected result of this expression is 1.
toWord16 (toWord64 77)
This expression converts a 64-bit unsigned integer to a 16-bit unsigned integer. The expected result of this expression is 77.
toWord16 (toWord64 (2**17 + 2))
This expression converts a large 64-bit unsigned integer to a 16-bit unsigned integer. The expected result of this expression is 2.
toWord32 (toWord64 77)
This expression converts a 64-bit unsigned integer to a 32-bit unsigned integer. The expected result of this expression is 77.
toWord32 (toWord64 (2**33 + 5))
This expression converts a large 64-bit unsigned integer to a 32-bit unsigned integer. The expected result of this expression is 5.
toWord64 (toWord16 (2**62 + 1))
This expression converts a large 16-bit unsigned integer to a 64-bit unsigned integer. The expected result of this expression is 1.
fromWord (toWord64 (2**62))
This expression converts a large unsigned integer to a signed integer. The expected result of this expression is 4611686018427387904.
fromWord (toWord32 (2**62 + 2**31))
This expression converts a large unsigned integer to a signed integer. The expected result of this expression is 2147483648.
fromWord (toWord16 (2**31 + 2**3))
This expression converts a large unsigned integer to a signed integer. The expected result of this expression is 8.