Fork me on GitHub
Source file: literate-files.fut

Reading and writing files in literate Futhark

Futhark is not a general purpose language, but futhark literate can read files and pass their contents to Futhark entry points. Sometimes that is enough to do interesting things. File contents are provided as values of type []u8, meaning the raw bytes. Any text decoding must be done manually, if applicable.

def rev_first_n (n: i64) (s: []u8) = reverse (take n s)

Reading a file is done with the $loadbytes builtin, which is only valid in FutharkScript.

> rev_first_n 10 ($loadbytes "literate-files.fut")
[105u8, 100u8, 97u8, 101u8, 82u8, 32u8, 35u8, 32u8, 45u8, 45u8]

See also

The other Literate Futhark examples.