std
deep_seq : forall a. Dyn -> a -> a
deep_seq x y
forces a deep evaluation x
, before returning y
. Deep
evaluation means deep_seq
recursively forces the evaluation of
the content of records and arrays, as opposed to std.seq
.
Examples
std.deep_seq (42 / 0) 37
# => error
std.deep_seq (42 / 2) 37
# => 37
std.deep_seq [1+1, { not_too_far = [42 / 0] }] 37
# => error
deserialize : [| 'Json, 'Toml, 'Yaml |] -> String -> Dyn
Deserializes a string into a Nickel value from the given representation.
Examples
deserialize 'Json "{ \"hello\": \"Hello\", \"world\": \"World\" }"
# => { hello = "Hello", world = "World" }
fail_with | String -> Dyn
Abort the evaluation with the given message. The error will be reported as
a contract violation, as fail_with
uses std.FailWith
under the hood.
Examples
std.fail_with "message"
# => error: message
FailWith
A contract that always fails with the given message.
Examples
1 | std.FailWith "message"
# => error: message
hash : [| 'Md5, 'Sha1, 'Sha256, 'Sha512 |] -> String -> String
Hashes the given string with the desired hashing algorithm.
Examples
std.hash 'Md5 "hunter2"
# => "2ab96390c7dbe3439de74d0c9b0b1767"
is_array : Dyn -> Bool
Checks if a value is an array.
Examples
std.is_array [ 1, 2 ]
# => true
std.is_array 42
# => false
is_bool : Dyn -> Bool
Checks if a value is a bool.
Examples
std.is_bool false
# => true
std.is_bool 42
# => false
is_enum : Dyn -> Bool
Checks if a value is an enum tag.
Examples
std.is_enum true
# => false
std.is_enum 'false
# => true
is_function : Dyn -> Bool
Checks if a value is a function.
Examples
std.is_function (fun x => x)
# => true
std.is_function 42
# => false
is_number : Dyn -> Bool
Checks if a value is a number.
Examples
std.is_number 1
# => true
std.is_number "Hello, World!"
# => false
is_record : Dyn -> Bool
Checks if a value is a record.
Examples
std.is_record [ 1, 2 ]
# => false
std.is_record { hello = "Hello", world = "World" }
# => true
is_string : Dyn -> Bool
Checks if a value is a string.
Examples
std.is_string true
# => false
std.is_string "Hello, World!"
# => true
seq : forall a. Dyn -> a -> a
seq x y
forces the evaluation of x
, before returning y
.
The evaluation of x
stops as soon as a so-called weak head normal form
is reached, which is either:
- an array
- a record
- a function (or a match statement, which is function in disguise)
- a constant (a number, a boolean, a string literal or an enum tag)
- a contract label
Note that seq
won't evaluate the content of arrays and records
further. Please see std.deep_seq
to recursively force the
evaluation of an expression.
Examples
std.seq (42 / 0) 37
# => error
std.seq (42 / 2) 37
# => 37
std.seq { too_far = 42 / 0 } 37
# => 37
serialize : [| 'Json, 'Toml, 'Yaml |] -> Dyn -> String
Serializes a value into the desired representation.
Examples
serialize 'Json { hello = "Hello", world = "World" }
# => "{\n \"hello\": \"Hello\",\n \"world\": \"World\"\n}"
to_string | std.string.Stringable -> String
Converts a stringable value to a string representation. Same as
std.string.from
.
Examples
std.to_string 42
# => "42"
std.to_string 'Foo
# => "Foo"
std.to_string null
# => "null"
trace : forall a. String -> a -> a
std.trace msg x
prints msg
to standard error, then proceeds with
the evaluation of x
.
Examples
std.trace "Hello, world!" true
# std.trace: Hello, world!
# => true
typeof : Dyn
-> [|
'"Number",
'"Bool",
'"String",
'Enum,
'Label,
'Function,
'"Array",
'Record,
'ForeignId,
'CustomContract,
'Type,
'Other
|]
Returns the type of a value.
Examples
std.typeof [ 1, 2 ]
# => 'Array
std.typeof (fun x => x)
# => 'Function