Skip to content
barbuz edited this page Oct 30, 2017 · 80 revisions

This page documents the currently implemented commands of Husk in the order that they appear on the codepage.

Char Alias Name Type Description
¤ cur combin (y -> y -> z) -> (x -> y) -> x -> x -> z Compose both arguments of binary function
½ hlf halve TNum -> TNum Divide by 2
islowr TChar -> TNum Is it a lowercase letter
halfL [x] -> [[x]] Split a list into two halves. If the length is odd, the first half will be longer.
ud span (Concrete y) => (x -> y) -> [x] -> ([x], [x]) Split at first value where function gives falsy result
up take TNum -> [x] -> [x] Take n elements from list. Negative n takes from the end
take2 [x] -> TNum -> [x] Flipped version of take
takew (Concrete y) => (x -> y) -> [x] -> [x] Longest prefix where function gives truthy result
dow drop TNum -> [x] -> [x] Drop n elements from list. Negative n drops from the end
drop2 [x] -> TNum -> [x] Flipped version of drop
dropw (Concrete y) => (x -> y) -> [x] -> [x] Drop longest prefix where function gives truthy result
lr swap (x, y) -> (y, x) Swap a pair
rev [x] -> [x] Reverse a list
lft head [x] -> x First value of a list
fst (x, y) -> x Left value of a pair
predN TNum -> TNum Decrement number
predC TChar -> TChar Decrement character
rgt last [x] -> x Last value of a list
snd (x, y) -> y Right value of a pair
succN TNum -> TNum Increment number
succC TChar -> TChar Increment character
\n Newline Separates lines in program
¦ bar divds TNum -> TNum -> TNum Does first argument divide the second
¡ exc iter (x -> x) -> x -> [x] Apply function repeatedly, collect values in infinite list
iterP ([x] -> x) -> [x] -> [x] Apply function repeatedly, obtaining a new value from the list of previous ones
iterL (x -> [x]) -> [x] -> [x] Apply function repeatedly, concatenate results into infinite list
iter2 (x -> (x, y)) -> x -> [y] Apply function repeatedly to first result, collect second results into infinite list
dex twice (x -> x) -> (x -> x) Apply function twice
ell rangeN TNum -> TNum -> [TNum] Inclusive numeric range
rangeC TChar -> TChar -> [TChar] Inclusive character range
rangeL [TNum] -> [TNum] Fill gaps with numeric ranges
rangeS [TChar] -> [TChar] Fill gaps with character ranges
ppm mod1 TNum -> TNum -> TNum Like mod, but result is in range [1 .. n] ([n .. -1] for negative n)
dag vec (Vect a b x y) => (a -> b) -> x -> y Vectorize a function ("deep map")
ddg vec2 (Vect2 a b c x y z) => (a -> b -> c) -> x -> y -> z Bi-vectorize a function ("deep zip")
srd sqrt TNum -> TNum Square root
isalph TChar -> TNum Is it a letter
leq le (Concrete x) => x -> x -> TNum Less than or equal
geq ge (Concrete x) => x -> x -> TNum Greater than or equal
± pm sign TNum -> TNum Sign of a number
isdigt TChar -> TNum Is it a digit
ptl adiags [[x]] -> [[x]] Antidiagonals
int cumsum [TNum] -> [TNum] Cumulative sum
cumcat [[a]] -> [[a]] Cumulative concatenation
inf rep x -> [x] Infinite list of copies of the argument
apx simil (Concrete x) => x -> x -> TNum Similar. For numbers or chars checks if the absolute difference is <=1. For lists checks if they are the same length. For Pairs checks if both elements are similar.
neq neq (Concrete x) => x -> x -> TNum Not equal
cng congr (Concrete x) => x -> x -> TNum Recursively check if the two arguments have the same shape and the same distribution of truthy/falsy values. Returns 1 or 0.
¬ neg not (Concrete x) => x -> TNum Negation of truthiness
÷ div idiv TNum -> TNum -> TNum Integer division
× eks mix (x -> y -> z) -> [x] -> [y] -> [z] Function applied to all pairs drawn from the lists
Space Token separator, flag for multi-digit labels and marked lines
! index TNum -> [x] -> x Value at modular index
index2 [x] -> TNum -> x index with flipped arguments
\ inv TNum -> TNum Reciprocal number
swcase TChar -> TChar Swap case
" Double quote String delimiter
# countf (Concrete y) => (x -> y) -> [x] -> TNum Number of list elems where function result is truthy
count (Concrete x) => x -> [x] -> TNum Number of occurrences of value in list
count2 (Concrete y) => (x -> x -> y) -> [x] -> TNum Number of adjacent pairs of elements where function result is truthy
% mod TNum -> TNum -> TNum Modulus of second argument by first
& and (Concrete x) => x -> x -> x Second argument if falsy, else first
and' (Concrete x, Concrete y) => x -> y -> TNum Are both arguments truthy?
' Single quote Character delimiter
() Parentheses Group expressions
* mul TNum -> TNum -> TNum Multiply numbers
+ add TNum -> TNum -> TNum Add numbers
cat [x] -> [x] -> [x] Concatenate lists
, pair x -> y -> (x, y) Construct pair
- sub TNum -> TNum -> TNum Subtract first argument from second
diffl (Concrete x) => [x] -> [x] -> [x] List difference
del (Concrete x) => x -> [x] -> [x] Remove first occurrence of element from list
. Decimal point Used in floating point literals
/ div TNum -> TNum -> TNum Floating point division
0-9 Digits Used in numeric literals
: cons x -> [x] -> [x] Prepend a value to a list
snoc [x] -> x -> [x] Append a value to a list
; pure x -> [x] Create singleton list
< lt (Concrete x) => x -> x -> TNum Less than
= eq (Concrete x) => x -> x -> TNum Equals
> gt (Concrete x) => x -> x -> TNum Greater than
? if (Concrete x) => y -> y -> x -> y Ternary if conditioned on third argument
if2 (Concrete x) => (x -> y) -> y -> x -> y If truthy, apply function, else give default value
fif (Concrete x) => (z -> y) -> (z -> y) -> (z -> x) -> z -> y Ternary if for functions
B base TNum -> TNum -> [TNum] Digits in given base
abase TNum -> [TNum] -> TNum Interpret as digits in given base
C cut TNum -> [a] -> [[a]] Cut into sublists of given length. Negative n counts lengths from the end.
cuts [TNum] -> [a] -> [[a]] Cut off substrings of given lengths. Negative n cuts from the end.
D double TNum -> TNum Multiply by 2
isuppr TChar -> TNum Is it an uppercase letter
doubL [x]->[x] Repeats a list twice
E same Concrete x => [x] -> TNum Are all elements equal?
F foldl (y -> x -> y) -> y -> [x] -> y Left fold
foldl1 (x -> x -> x) -> [x] -> x Left fold without initial value
aptp (x -> y -> z) -> (x, y) -> z Apply binary function to tuple
G scanl (y -> x -> y) -> y -> [x] -> [y] Scan from left
scanl1 (x -> x -> x) -> [x] -> [x] Scan from left without initial value
scltp (x -> y -> z) -> (x, y) -> (z, y) Apply binary function to tuple, updating left element
I id x -> x Identity function
J join [x] -> [[x]] -> [x] Join by a list
join' x -> [[x]] -> [x] Join by an element
joinE [x] -> [x] -> [x] Join elements by a list
K const x -> y -> x Constant function
L len [x] -> TNum Length of list
nlen TNum -> TNum Length of string representation
M lmap (x -> y -> z) -> [x] -> y -> [z] Map over left argument
lmaptp (x -> z) -> (x, y) -> (z, y) Apply function to left element of tuple
N nats [TNum] Infinite list of natural numbers
O sort (Concrete x) => [x] -> [x] Sort list in ascending order
P perms [a] -> [[a]] List of all permutations of the given list
Q slices [a] -> [[a]] All contiguous sublists
R replic TInt -> a -> [a] List composed by a given number of copies of a value
replif a -> TInt -> [a] replic with flipped arguments
S hook (x -> y -> z) -> (x -> y) -> x -> z S-combinator
bhook (x -> y -> z) -> (x -> u -> y) -> x -> u -> z S-combinator with extra argument: S f g a b means f a (g a b)
T trsp [[a]] -> [[a]] Transpose a 2-d list, elements missing from shorter rows are skipped
trspw a -> [[a]] -> [[a]] Transpose using the given element to pad shorter rows
U nubw Concrete a => [a] -> [a] Longest prefix of a list with all unique elements
V any Concrete b => (a->b) -> [a] -> TNum Index of first element satisfying predicate, 0 if not found
any2 Concrete b => (a->a->b) -> [a] -> TNum Index of first element satisfying the predicate in respect to the next element in the list, 0 if not found
X slice TNum -> [a] -> [[a]] All subslists of length n. Negative n includes final stubs.
^ power TNum -> TNum -> TNum Second argument raised to the power of the first
_ neg TNum -> TNum Negate a number
tolowr TChar -> TChar Covert to lowercase
` flip (x -> y -> z) -> y -> x -> z Invert order of arguments
a abs TNum -> TNum Absolute value
touppr TChar -> TChar Convert to uppercase
c chr TNum -> TChar Convert integer to character
ord TChar -> TNum Convert character to integer
chrL [TNum] -> [TChar] Convert list of codepoints to string
ordL [TChar] -> [TNum] Convert string to list of codepoints
d base10 TNum -> [TNum] Base-10 digits
abas10 [TNum] -> TNum Interpret in base 10
e list2 x -> x -> [x] Create a list with two elements
f filter (Concrete y) => (x -> y) -> [x] -> [x] Filter list by predicate
select (Concrete x) => [x] -> [y] -> [y] Filter list by another list
g group (Concrete x) => [x] -> [[x]] Group equal adjacent values
h init [x] -> [x] Remove last element
i d2i TDouble -> TNum Convert from Double to Int by rounding (round half to even)
c2i TChar -> TNum Chars in "0123456789" return their digit value, other Chars return 0
s21 [TChar] -> TNum Return the first integer found inside the string
m map (x -> y) -> [x] -> [y] Map function over list
mapr [x -> y] -> x -> [y] Map list of functions over value
maptp (x -> y) -> (x, x) -> (y, y) Map function over tuple
o com (y -> z) -> (x -> y) -> x -> z Function composition
com2 (z -> u) -> (x -> y -> z) -> x -> y -> u Binary composition
com3 (u -> v) -> (x -> y -> z -> u) -> x -> y -> z -> v Ternary composition
com4 (v -> w) -> (x -> y -> z -> u -> v) -> x -> y -> z -> u -> w Quaternary composition
p pfac TNum -> [TNum] Prime factorization
r read (Concrete x) => [TChar] -> x Convert string to value
s show (Concrete x) => x -> [TChar] Convert value to string
t tail [x] -> [x] Remove first element
u nub (Concrete x) => [x] -> [x] Remove duplicates
w words [TChar] -> [[TChar]] Split on spaces
unwords [[TChar]] -> [TChar] Join with spaces
uwshow Concrete x => [x] -> [TChar] Join string representations with spaces
z zip (x -> y -> z) -> [x] -> [y] -> [z] Zip lists with function
| or (Concrete x) => x -> x -> x Second argument if truthy, else first
or' (Concrete x, Concrete y) => x -> y -> TNum Is any of the arguments truthy?
~ branch (x -> y -> z) -> (u -> x) -> (v -> y) -> (u -> v -> z) Compose both arguments of binary function separately
- nul-nin Subscript digits Line labels
lce ceil TNum -> TNum Ceiling function
rce lcm TNum -> TNum -> TNum Lowest common multiple
lfl floor TNum -> TNum Floor function
rfl gcd TNum -> TNum -> TNum Greatest common divisor
Γ Gam list y -> (x -> [x] -> y) -> [x] -> y Pattern match on list
listN (x -> [x] -> y) -> [x] -> y Pattern match on nonempty list
listF y -> (([x] -> y) -> (x -> [x] -> y)) -> [x] -> y Recursive pattern match on list
listNF (([x] -> y) -> (x -> [x] -> y)) -> [x] -> y Recursive pattern match on nonempty list
Θ The prep0 [x]->[x] Prepends a default value of the appropriate type to a list. Default values are either falsy values (0,[],...) or functions returning those values.
Λ Lam all Concrete b => (a->b) -> [a] -> TNum Check if all elements satisfy predicate, return 1/0
all2 Concrete b => (a->a->b) -> [a] -> TNum Check if all adjacent pairs of elements satisfy the predicate, return 1/0
Ξ Xi merge Concrete b => (a -> a -> b) -> [[a]] -> [a] Ξ f x merges the list of lists x preserving the order given by f. Each list should be ordered, and if there are more than 2 lists, their heads should also be ordered. Works on infinite lists.
merge2 Concrete b => (a -> b) -> [[a]] -> [a] Like merge, but preserves order obtained by applying f to each value.
Π Pi prod [TNum] -> TNum Product of list
fact TNum -> TNum Factorial
cartes [[x]] -> [[x]] Cartesian product
Σ Sig sum [TNum] -> TNum Sum of list
trianI TNum -> TNum Triangular number
concat [[x]] -> [x] Concatenate lists
Ψ Psi toadjM (((a, a) -> c) -> [(a,a)] -> [[(a, a)]]) -> (a -> a -> c) -> [a] -> [[a]] Apply higher-order function on adjacent pairs instead of single elements
toadjL (((a, a) -> c) -> [(a,a)] -> [(a, a)]) -> (a -> a -> c) -> [a] -> [a] Like toadjL but result is a flat list
toadjV (((a, a) -> c) -> [(a,a)] -> (a, a)) -> (a -> a -> c) -> [a] -> a Like toadjL but result is an element
toadjN (((a, a) -> c) -> [(a,a)] -> b) -> (a -> a -> c) -> [a] -> b Like toadjL but result is any value
Ω Ohm until Concrete y => (x -> y) -> (x -> x) -> x -> x Iterate function until test result is truthy
ε eps small TNum -> TNum Has absolute value at most 1
single [x] -> TNum Has length 1
δ del decorM (((a, b) -> c) -> [(a,b)] -> [[(a,d)]]) -> (a -> b -> c) -> [a] -> [b] -> [[d]] Apply higher-order function using auxiliary list
decorL (((a, b) -> c) -> [(a,b)] -> [(a,d)]) -> (a -> b -> c) -> [a] -> [b] -> [d] Like decorM but result is a flat list
decorV (((a, b) -> c) -> [(a,b)] -> (a,d)) -> (a -> b -> c) -> [a] -> [b] -> d Like decorM but result is an element
decorN (((a, b) -> c) -> [(a,b)] -> d) -> (a -> b -> c) -> [a] -> [b] -> d Like decorM but result is any value
λ lam Small lambda One-argument anonymous function
μ mu Small mu Two-argument anonymous function
ξ xi Small xi Three-argument anonymous function
σ sjg subs (Concrete x) => x -> x -> [x] -> [x] Substitute value in list
subs2 (Concrete x) => [x] -> [x] -> [x] -> [x] Substitute sublist in list
φ phi Small phi Self-referential anonymous function
χ chi Small chi Self-referential anonymous function with 2 extra arguments
ψ psi Small psi Self-referential anonymous function with extra argument
ω ohm fixp (Concrete x) => (x -> x) -> x -> x Find periodic point by iterating
fixpL (Concrete x) => (x -> [x]) -> x -> [x] Find periodic point under concatenation
- Nul-Nin Superscript digits Lambda arguments
¢ cnt cycle [x] -> [x] Repeat list infinitely
£ gbp oelem (Concrete x) => [x] -> x -> TNum Like elem, but the list is supposed to be sorted
oelem' (Concrete x) => x -> [x] -> TNum oelem with flipped arguments
eur elem (Concrete x) => [x] -> x -> TNum Index of first occurrence, or 0 if not found
elem' (Concrete x) => x -> [x] -> TNum elem with flipped arguments
subl (Concrete x) => [x] -> [x] -> TNum Index of first beginning of the sublist, or 0 if not found
ƒ fl fix (x -> x) -> x Least fixed point (used for recursion)
´ acu argdup (x -> x -> y) -> x -> y Apply twice to same argument
top max (Concrete x) => x -> x -> x Maximum of two values
maxl (Concrete x) => [x] -> x Maximum of list
bot min (Concrete x) => x -> x -> x Minimum of two values
minl (Concrete x) => [x] -> x Minimum of list
est minby Concrete y => (x -> x -> y) -> x -> x -> x Minimum of two values with custom ordering predicate
minon Concrete y => (x -> y) -> x -> x -> x Value that minimizes function result
minlby Concrete y => (x -> x -> y) -> [x] -> x Minimum element with custom ordering predicate
minlon Concrete y => (x -> y) -> [x] -> x Element that minimizes function result
wst maxby Concrete y => (x -> x -> y) -> x -> x -> x Maximum of two values with custom ordering predicate
maxon Concrete y => (x -> y) -> x -> x -> x Value that maximizes function result
maxlby Concrete y => (x -> x -> y) -> [x] -> x Maximum element with custom ordering predicate
maxlon Concrete y => (x -> y) -> [x] -> x Element that maximizes function result
§ sec fork (x -> y -> z) -> (u -> x) -> (u -> y) -> u -> z Compose each argument of binary function
fork2 (x -> y -> z) -> (u -> v -> x) -> (u -> v -> y) -> u -> v -> z Compose each argument of binary function with binary function
dD divs TNum -> [TNum] List of divisors
dF foldr (x -> y -> y) -> y -> [x] -> y Right fold
foldr1 (x -> x -> x) -> [x] -> x Right fold without initial value
apftp (y -> x -> z) -> (x, y) -> z Apply flipped function to tuple
Ġ dG scanr (x -> y -> y) -> y -> [x] -> [y] Scan from right
scanr1 (x -> x -> x) -> [x] -> [x] Scan from right without initial value
scrtp (x -> y -> z) -> (x, y) -> (x, z) Apply binary function to tuple, updating right element
İ dI Dotted capital I Access built-in integer sequences
dM rmap (x -> y -> z) -> x -> [y] -> [z] Map over right argument
rmaptp (y -> z) -> (x, y) -> (x, z) Apply function to right element
dP powset [x] -> [[x]] All finite subsequences
powstN TNum -> [x] -> [[x]] Subsequences of length n. Negative n gives subsequences of length up to -n.
dR clone TNum -> [x] -> [x] Replicate each element by given number
clone' [x] -> TNum -> [x] clone with flipped arguments
clones [TNum] -> [x] -> [x] Replicate each element by corresponding number
dS hookf (x -> y -> z) -> (y -> x) -> y -> z Like S, but composes on other argument
bhookf (x -> y -> z) -> (u -> y -> x) -> u -> y -> z Like binary S, but composes on other argument: Ṡ f g a b means f (g a b) b
dT table (x -> y -> z) -> [x] -> [y] -> [[z]] Outer product, or "multiplication table"
dX mapad2 (x -> x -> y) -> [x] -> [y] Map over pairs of adjacent values
mapad3 (x -> x -> x -> y) -> [x] -> [y] Map over triples of adjacent values
dd base2 TNum -> [TNum] Binary digits
abase2 [TNum] -> TNum Interpret in base 2
ė de list3 x -> x -> x -> [x] Create a list with three elements
df find (Concrete y) => (x -> y) -> [x] -> x Return first value that gives truthy result
findN (Concrete x) => (TNum -> x) -> TNum -> TNum Return first number at least n that gives truthy result
ġ dg groupOn (Concrete y) => (x -> y) -> [x] -> [[x]] Group on function result
groupBy (Concrete y) => (x -> x -> y) -> [x] -> [[x]] Group by equality predicate
dh heads (Concrete x) => x -> [x] Prefixes for lists, range for numbers
ŀ dl lrange TNum -> [TNum] Lowered range (from 0 to n-1)
ixes [x] -> [TNum] The range [1 .. length(x)]
dm cmap (x -> [y]) -> [x] -> [y] Map function over list and concat the result
smap (x -> TNum) -> [x] -> TNum Map function over list and sum the result
cmapr [x -> [y]] -> x -> [y] Map list of functions over value and concat the result
smapr [x -> TNum] -> x -> TNum Map list of functions over value and sum the result
ȯ do Too many to list Composition of three functions; ȯABC is roughly equivalent to (ABC)
dp isprime TNum -> TNum Return the index of the argument in the list of all primes, or 0 if it is not a prime number
dr rotate TNum -> [a] -> [a] Rotate n steps to the left
rotatf [a] -> TNum -> [a] rotate with flipped arguments
ds srange TNum -> [TNum] Symmetric range (from -n to n)
rvixes [x] -> [TNum] ixes reversed
dt tails (Concrete x) => x -> [x] Suffixes for lists, reversed range for numbers
ż dz zip' (a -> a -> a) -> [a] -> [a] -> [a] Like zip, but keeps trailing elements from the longer list unchanged.
¨ die Dieresis Delimiter for compressed strings
Ö DO sorton (Concrete y) => (x -> y) -> [x] -> [x] Sort by function result
sortby (Concrete y) => (x -> x -> y) -> [x] -> [x] Sort using ordering predicate. In Ö p, p x y is interpreted as "x is greater than y".
ë De list4 x -> x -> x -> x -> [x] Create a list with four elements
ö Do Too many to list Composition of four functions; öABCD is roughly equivalent to (ABCD)
ü Du nubon (Concrete x) => (x -> y) -> [x] -> [x] Remove duplicates by function result
nubby (Concrete x) => (x -> x -> y) -> [x] -> [x] Remove duplicates using equality predicate
ø so empty [x] Empty list
squ square TNum -> TNum Raise to second power
isanum Is it alphanumeric
pgf lines [TChar] -> [[TChar]] Split on newlines
unlines [[TChar]] -> [TChar] Join by newlines
ulshow Concrete x => [x] -> [TChar] Join string representations by newlines
« ll mapacL (x -> y -> x) -> (x -> y -> z) -> x -> [y] -> [z] Scanl over a list with the first function, but results are produced by applying the second function to intermediate steps
» rr mapacR (y -> x -> x) -> (y -> x -> z) -> x -> [y] -> [z] Scanr over a list with the first function, but results are produced by applying the second function to intermediate steps

Modifier functions

This is the list of functions applied to overflowing line labels:

| argdup | flip | map | zip | hook |

Clone this wiki locally