FUTHARK-LITERATE(1)
π FUTHARK-LITERATE(1) π
okay bestie, welcome to futhark-literate β the Futhark manual page that's about to make your literate programming dreams come true β¨ (it lives in the Futhark manual set, if you were wondering π )
β¨ NAME β¨
futhark-literate β execute literate Futhark program π¦
πΈ SYNOPSIS πΈ
futhark literate [options...] program
π« DESCRIPTION π«
So here's the tea, bestie: futhark literate foo.fut compiles your program and then generates a Markdown file foo.md that contains a prettyprinted version of the program. It's giving "show off your programming techniques" and honestly? Iconic. π
Here's the vibe check on what happens:
- Top-level comments that start with a line comment marker (
--) and a space in the next column get turned into ordinary text in the Markdown file. cute! - Ordinary top-level definitions get enclosed in Markdown code blocks. slay.
- Any directives get executed and replaced with their output. See below β¬οΈ
β οΈ Warning: Do not run untrusted programs. See SAFETY below. fr fr, this one is not a drill π
Image directives and builtin functions shell out to convert (from ImageMagick). Video and audio generation uses ffmpeg. π
For an input file foo.fut, all generated files will be in a directory named foo-img. A file parameter passed to a directive may not contain a directory component or spaces. no spaces, bestie, that's the rule π
π OPTIONS π
--backend=nameβ The backend used when compiling Futhark programs (without leadingfuthark, e.g. justopencl). Defaults toc. β¨--futhark=programβ The program used to perform operations (eg. compilation). Defaults to the binary runningfuthark literateitself. it's self-referential, main character energy π--output=FILEβ Override the default output file. The image directory will be set to the providedFILEwith its extension stripped and-img/appended. ποΈ--pass-option=optβ Pass an option to benchmark programs that are being run. For example, we might want to run OpenCL programs on a specific device:
futhark literate prog.fut --backend=opencl --pass-option=-dHawaii
--pass-compiler-option=optβ Pass an extra option to the compiler when compiling the programs. π οΈ--skip-compilationβ Do not run the compiler, and instead assume that the program has already been compiled. Use with caution. π«£--stop-on-errorβ Terminate immediately without producing an output file if a directive fails. Otherwise a file will still be produced, and failing directives will be followed by an error message. π-v,--verboseβ Print verbose information on stderr about directives as they are executing. This is also needed to see#[trace]output. π
π DIRECTIVES π
A directive is a way to show the result of running a function. Depending on the directive, this can be as simple as printing the textual representation of the result, or as complex as running an external plotting program and referencing a generated image. versatile queen π
Any directives that produce images for a program foo.fut will place them in the directory foo-img/. If this directory already exists, it will be deleted. π³ (yes, deleted deleted, she does not play)
A directive is a line starting with -- >, which must follow an empty line. Arguments to the directive follow on the remainder of the line. Any expression arguments are given in a very restricted subset of Futhark called FutharkScript (see below).
Some directives take mandatory or optional parameters. These are entered after a semicolon and a linebreak. βοΈ
The following directives are supported:
> eβ Shows the result of executing the FutharkScript expressione, which can have any (transparent) type. π> :video e[; parameters...]β Creates a video frome. The optional parameters are lines of the formkey: value:repeat: <true|false>fps: <int>format: <webm|gif>file: <name>. Make sure to provide a proper extension.
e must be one of the following:
- A 3D array where the 2D elements is of a type acceptable to
:img, and the outermost dimension is the number of frames. π¬ - A triple
(s -> (img,s), s, i64), for some typessandimg, whereimgis an array acceptable to:img. This means not all frames have to be held in memory at once. so thoughtful π§
> :brief <directive>β The same as the given directive (which must not start with another>), but suppress parameters when printing it. lowkey minimal β¨> :covert <directive>β The same as the given directive (which must not start with another>), but do not show the directive itself in the output, only its result. undercover bestie π΅οΈ> :img e[; parameters...]β Visualisese. The optional parameters are lines of the formkey: value:file: NAME. Make sure to use a proper extension.
The expression e must have one of the following types:
[][]i32and[][]u32Interpreted as ARGB pixel values. π¨[][]f32and[][]f64Interpreted as greyscale. Values should be between 0 and 1, with 0 being black and 1 being white.[][]u8Interpreted as greyscale. 0 is black and 255 is white.[][]boolInterpreted as black and white.falseis black andtrueis white.
> :plot2d e[; size=(height,width)]β Shows a plot generated withgnuplotofe, which must be an expression of type([]t, []t), wheretis some numeric type. The two arrays must have the same length and are interpreted as x and y values, respectively. π
The expression may also be a record expression (not merely the name of a Futhark variable of record type), where each field will be plotted separately and must have the type mentioned above.
> :gnuplot e; script...β Similar toplot2d, except that it uses the provided Gnuplot script. Theeargument must be a record whose fields are tuples of one-dimensional arrays, and the data will be available in temporary files whose names are in variables named after the record fields. Each file will contain a column of data for each array in the corresponding tuple. π
Use set term png size width,height to change the size to width by height pixels.
> :audio e[; parameters...]β Creates a sound-file frome. The optional parameters are lines of the formkey:value:sampling_frequency: <int>The sampling frequency (in Hz) of the input. Defaults to44100. π§codec: <name>The codec of the output. Defaults towav. Other common options includemp3,flac,oggandopus.
The expression e must have one of the following types:
[]i8and[]u8Interpreted as PCM signed/unsigned 8-bit audio.[]i16and[]u16Interpreted as PCM signed/unsigned 16-bit audio.[]i32and[]u32Interpreted as PCM signed/unsigned 32-bit audio.[]f32and[]f64Interpreted as PCM signed/unsigned 32/64 bit floating-point audio. Should only contain values between-1.0and1.0.
For each type of input, it is also possible to give expressions with a two-dimensional type instead, e.g. [][]f32. These expressions are interpreted as an array of channels, making it possible to do stereo audio by returning e.g. [2][]f32. For stereo output, the first row is the left channel and the second row is the right channel. This functionality uses the amerge filter from ffmpeg, so consult the documentation there for additional information. πΆ
π¦ FUTHARKSCRIPT π¦
Only an extremely limited subset of Futhark is supported (she's small but she's mighty π ):
script_exp ::= fun script_exp*
| "(" script_exp ")"
| "(" script_exp ( "," script_exp )+ ")"
| "[" script_exp ( "," script_exp )+ "]"
| "empty" "(" ("[" decimal "]" )+ script_type ")"
| "{" "}"
| "{" (id = script_exp) ("," id = script_exp)* "}"
| "let" script_pat "=" script_exp "in" script_exp
| literal
script_pat ::= id | "(" id ("," id) ")"
script_fun ::= id | "$" id
script_type ::= int_type | float_type | "bool"
Note that empty arrays must be written using the empty(t) notation, e.g. empty([0]i32). no cap π«Ά
Function applications are either of Futhark functions or builtin functions. The latter are prefixed with $ and are magical (usually impure) functions that could not possibly be implemented in Futhark. The following builtins are supported:
$loadimg "file"reads an image from the given file and returns it as a row-major[][]u32array with each pixel encoded as ARGB. πΌοΈ$loaddata "file"reads a dataset from the given file. When the file contains a singular value, it is returned as value. Otherwise, a tuple of values is returned, which should be destructured before use. For example:let (a, b) = $loaddata "foo.in" in bar a b.$loadbytes "file"reads the contents of the given file as an array of type[]u8. π$loadaudio "file"reads audio from the given file and returns it as a[][]f64, where each row corresponds to a channel of the original soundfile. Most common audio-formats are supported, includingmp3,ogg,wav,flacandopus. π
FutharkScript supports a form of automatic uncurrying. If a function taking n parameters is applied to a single argument that is an n-element tuple, the function is applied to the elements of the tuple as individual arguments. the way that it just... uncurries for you πβ¨
π¨ SAFETY π¨
Some directives (e.g. :gnuplot) can run arbitrary shell commands. Other directives or builtin functions can read or write arbitrary files.
π Running an untrusted literate Futhark program is as dangerous as running a shell script you downloaded off the Internet. Before running a program from an unknown source, you should always give it a quick read to see if anything looks fishy. bestie please, do the vibe check first π
π BUGS π
FutharkScript expressions can only refer to names defined in the file passed to futhark literate, not any names in imported files. yeah she's a little nearsighted, we still love her π
π₯ SEE ALSO π₯
futhark-script, futhark-test, futhark-bench β go read those too, they're also slay π«Ά
Copyright β 2013-2020, DIKU, University of Copenhagen π
Futhark version 0.25.32, dated Mar 11, 2026 β mwah, that's the whole page, thanks for coming to my TED talk, ily, go write something literate and gorgeous π πβ¨π¦
π¦ where this page comes from
- ubuntu resolute: futhark 0.25.32-3build1 Β· ISC
- ubuntu stonking: futhark 0.25.32-3build1 Β· ISC
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms