concat(Vec<T, n>, Vec<T, m>) -> Vec<T, n+m>
matmul(Mat<T, n, m>, Mat<T, m, l>) -> Mat<T, n, l>
head(Vec<T, n+1>) -> (T, Vec<T, n>)
This would have saved me so much headache debugging CUDA kernels and numpy!! I wish it were a first-class feature in those frameworks, and even general-purpose languages, but alas. val concat [n] [m] 't : (xs: [n]t) -> (ys: [m]t) -> *[n + m]t
val matmul [n] [m] [l] 't : (xs: [n][m]t) -> (ys: [m][l]t) -> *[n][l]t
val head [n] 't : (x: [n]t) -> t
And here's the pathological case (length cannot be determined at compile time): val filter [n] 'a : (p: a -> bool) -> (as: [n]a) -> *[]a
Other pathological cases include conditionals and loops.Now I'm thinking about "Smalltalk by Example" and "Slang by Example"
For those that don't know, Futhark is comes from the first 6 letters of the runic alphabet (F, U, Þ, A, R, K)
argv: Vec<String, argc>
If I want to map these to ints, then I'd like a compile-time guarantee that the resulting array nums: Vec<Int, argc>
is the same length as argv. Lean and Idris can do this, but AFAIK no commonly used languages can. But unlike general dependent types, these are not hard to wrap one's head around and would save a lot of frustration, in my experience.[1] https://archive.org/details/karlsson-thomas-uthark-nightside...
[2] https://www.84cxrarebooks.com/pages/books/090763/t-ketola-th...
[3] https://www.miskatonicbooks.com/product/thursakyngi-iv-svart...
The following is a hands-on introduction to Futhark through a collection of commented programs, listed in roughly increasing order of complexity. You can load the programs into the interpreter to experiment with them. For a conventional introduction to the language, Parallel Programming in Futhark may be a better choice. For more examples, you can check our implemented benchmarks. We also maintain a list of projects using Futhark.
Some of the example programs use directives for plotting or rendering graphics.
Literate Futhark allows direct use of gnuplot. These examples show simple and common cases.
The following examples are ported from Dex, a dependently typed functional array language that uses a somewhat different approach to describing loop processing. We've tried to keep the original naming scheme and programming style.
The majority of written Futhark code is probably still Futhark’s own test and benchmark suites. However, there are some programs that have been written in Futhark because it was a good tool for the job, and not just to test the compiler. A possibly incomplete list:
Diving Beet is a falling sand game, which is a kind of simple particle simulator toy. Its main purpose is to produce pretty effects. There is a blog post with details and a video.
Futball is a game about avoiding getting hit by balls. The rendering engine is a ray tracer written in Futhark.
Futcam is an application that applies stacks of interactively configurable filters to a webcam stream. Futhark is used to implement the filters.
Futracer is a fairly slow brute-force ray tracer written in Futhark.
Futswirl is a fractal generator based on iterated function systems.
Neptune is an implementation of the Poseidon hash function tuned for Filecoin, where the GPU parts have been implemented in Futhark.
Palathark is a Futhark implementation of the lattice Boltzmann method.
Ray Tracing in One Weekend in Futhark and Ray Tracing: the Next Week in Futhark are implementations based on Peter Shirley's book series. These are by no means real-time ray tracers, but support advanced effects and make use of acceleration structures like BVH trees.
Pareas is a compiler implemented in Futhark and C++.