polar

Built-in Modules

These modules are part of the compiler, not the standard library. Every file can use them without a uses line.

String

Function Description
length(String) -> Int The number of characters, counted as Unicode code points
concat(String, String) -> String Joins two strings
contains(String, String) -> Bool Whether the second string appears in the first
starts_with(String, String) -> Bool Whether the first string starts with the second
ends_with(String, String) -> Bool Whether the first string ends with the second
slice(String, Int, Int) -> String The characters from the start index up to, but not including, the end index
split(String, String) -> List<String> Splits on a separator
replace(String, String, String) -> String Replaces every occurrence of the second string with the third
trim(String) -> String Removes surrounding whitespace
lowercase(String) -> String Lowercase copy
uppercase(String) -> String Uppercase copy
repeat(String, Int) -> String The string repeated a number of times
charCodeAt(String, Int) -> Int The UTF-16 code unit at an index, like JavaScript's charCodeAt
eq(String, String) -> Bool Equality, the same as ==

All of these work with the pipe, since the string comes first: text |> String.trim |> String.lowercase.

Int

Function Description
to_string(Int) -> String Decimal text
to_float(Int) -> Float The same number as a Float
parse(String) -> Option<Int> Reads an integer, or None if the text isn't one
to_base(Int, Int) -> String Text in another base: Int.to_base(5, 2) is "101"
eq(Int, Int) -> Bool Equality, the same as ==

Float

Function Description
to_string(Float) -> String Decimal text
to_int(Float) -> Int Drops the fractional part
floor(Float) -> Float Rounds down
abs(Float) -> Float Absolute value
sqrt(Float) -> Float Square root
sin(Float) -> Float, cos(Float) -> Float Sine and cosine, in radians
atan2(Float, Float) -> Float The angle of a point, from y and x
eq(Float, Float) -> Bool Equality, the same as ==

Std.Math has pi.

Bool

Function Description
to_string(Bool) -> String "true" or "false"
eq(Bool, Bool) -> Bool Equality, the same as ==

Log

Function Description
info(String) -> {} Prints a line to standard output, or console.log in the browser
error(String) -> {} Prints a line to standard error, or console.error in the browser

Note: Log is not an effect, so pure functions can log. It's meant for output and debugging, not for program logic.