The misc library

Miscellaneous functions.

Synopsis

_is_js :: Boole
pi :: 1

_list_all :: (List(Boole)) -> Boole
_list_concat :: (List(String)) -> String
_list_count :: (List(Boole)) -> 1
_list_gcd :: for_unit a, P!u, Q!v: for_index P, Q: (List(P! per Q!)) -> P! per Q!
_list_max :: for_unit a, P!u, Q!v: for_index P, Q: (List(a*P!u per Q!v)) -> a*P!u per Q!v
_list_min :: for_unit a, P!u, Q!v: for_index P, Q: (List(a*P!u per Q!v)) -> a*P!u per Q!v
_list_some :: (List(Boole)) -> Boole
_list_sum :: for_unit a, P!u, Q!v: for_index P, Q: (List(a*P!u per Q!v)) -> a*P!u per Q!v
approx_equal :: for_index P, Q: for_unit a, P!u, Q!v: (a*P!u per Q!v, a*P!u per Q!v) -> Boole
approximates :: for_unit a, I!u, J!v: for_index I, J: (a*I!u per J!v, a*I!u per J!v, decimals) -> Boole
approximates_to :: for_unit a, I!u, J!v: for_index I, J: (decimals) -> (a*I!u per J!v, a*I!u per J!v) -> Boole
catch :: for_type t: (() -> t) -> Result(t)
compare :: for_unit a: (a, a) -> 1
equiv :: (Boole, Boole) -> Boole
from_percentage :: for_index D, E: (percent*D! per E!) -> D! per E!
is_error :: for_type t: (Result(t)) -> Boole
is_something :: for_type a: (Maybe(a)) -> Boole
map_maybe :: for_type a, b: ((a) -> b, Maybe(a)) -> Maybe(b)
map_result :: for_type a, b: ((a) -> b, Result(a)) -> Result(b)
maybe :: for_type s, t: (() -> t, (s) -> t, Maybe(s)) -> t
now :: () -> milli:second
or_else :: for_type t: (t, Maybe(t)) -> t
or_else_get :: for_type t: (() -> t, Maybe(t)) -> t
printf :: for_type t: t -> Void
result_error :: for_type t: (Result(t)) -> String
result_or_else :: for_type t: (t, Result(t)) -> t
result_or_else_get :: for_type t: (() -> t, Result(t)) -> t
result_value :: for_type t: (Result(t)) -> t
to_percentage :: for_index D, E: (D! per E!) -> percent*D! per E!

Values

_is_js

:: Boole

pi

:: 1

Functions

_list_all

:: (List(Boole)) -> Boole

_list_concat

:: (List(String)) -> String

_list_count

:: (List(Boole)) -> 1

_list_gcd

:: for_unit a, P!u, Q!v: for_index P, Q: (List(P! per Q!)) -> P! per Q!

_list_max

:: for_unit a, P!u, Q!v: for_index P, Q: (List(a*P!u per Q!v)) -> a*P!u per Q!v

_list_min

:: for_unit a, P!u, Q!v: for_index P, Q: (List(a*P!u per Q!v)) -> a*P!u per Q!v

_list_some

:: (List(Boole)) -> Boole

_list_sum

:: for_unit a, P!u, Q!v: for_index P, Q: (List(a*P!u per Q!v)) -> a*P!u per Q!v

approx_equal

:: for_index P, Q: for_unit a, P!u, Q!v: (a*P!u per Q!v, a*P!u per Q!v) -> Boole

Are two matrices approximately equal?

Check that the difference between each corresponding entry from the two matrices is below some treshold. Uses the global precision().

TODO: check IEEE standards etc. This is a quick solution.

Defined as

approximates(A, B, precision())

approximates

:: for_unit a, I!u, J!v: for_index I, J: (a*I!u per J!v, a*I!u per J!v, decimals) -> Boole

approximates_to

:: for_unit a, I!u, J!v: for_index I, J: (decimals) -> (a*I!u per J!v, a*I!u per J!v) -> Boole

catch

:: for_type t: (() -> t) -> Result(t)

Catches errors from a function.

Calls the function. If an error occurs, the error message is captured and returned as part of the Result type.

compare

:: for_unit a: (a, a) -> 1

equiv

:: (Boole, Boole) -> Boole

from_percentage

:: for_index D, E: (percent*D! per E!) -> D! per E!

is_error

:: for_type t: (Result(t)) -> Boole

Is the Result an error?

is_something

:: for_type a: (Maybe(a)) -> Boole

Temporary stub for a proper Maybe type.

Is the Maybe not nothing?

map_maybe

:: for_type a, b: ((a) -> b, Maybe(a)) -> Maybe(b)

Temporary stub for a proper Maybe type.

Applies a function to a Maybe value.

map_result

:: for_type a, b: ((a) -> b, Result(a)) -> Result(b)

Applies a function to a Result value.

maybe

:: for_type s, t: (() -> t, (s) -> t, Maybe(s)) -> t

Temporary stub for a proper Maybe type.

Get a value from a Maybe.

The first argument is a function that provides a default value. If the Maybe is noting then this function is called and the result is returned.

If the Maybe has a value, then the function from the second argument is called on the value and the result is returned.

now

:: () -> milli:second

Number of milliseconds since some starting point.

or_else

:: for_type t: (t, Maybe(t)) -> t

Temporary stub for a proper Maybe type.

The first argument is a default value. If the Maybe is noting then this value is returned.

If the Maybe has a value, then that value is returned.

or_else_get

:: for_type t: (() -> t, Maybe(t)) -> t

Temporary stub for a proper Maybe type.

The first argument is a function that provides a default value. If the Maybe is noting then this function is called and the result is returned.

If the Maybe has a value, then that value is returned.

printf

:: for_type t: t -> Void

Prints formatted output.

Shorthand for

print(format(...))

For example

let n = 20 in
    printf("pi to %s decimals is %s", int2str(n, 1), num2string(pi, n, 1))
end;

prints

pi to 20 decimals is 3,14159265358979300000

result_error

:: for_type t: (Result(t)) -> String

Get the error message from a Result.

If the Result has a value, the empty string is returned.

result_or_else

:: for_type t: (t, Result(t)) -> t

The first argument is a default value. If the Result contains no value then this value is returned.

If the Result has a value, then that value is returned.

result_or_else_get

:: for_type t: (() -> t, Result(t)) -> t

Temporary stub for a proper Maybe type.

The first argument is a function that provides a default value. If the Result is an error then this function is called and the result is returned.

If the Result has a value, then that value is returned.

result_value

:: for_type t: (Result(t)) -> t

Get the value from a Result.

If the Result is an error, an error is signaled.

to_percentage

:: for_index D, E: (D! per E!) -> percent*D! per E!

Version v0.6.0, 2026-03-05T15:49:19.266584104+01:00[Europe/Amsterdam]