Skip to content

Instantly share code, notes, and snippets.

@sarahzrf
Created February 2, 2018 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sarahzrf/4fa7b1baf497d24ec7471ff3b02a44a8 to your computer and use it in GitHub Desktop.
Save sarahzrf/4fa7b1baf497d24ec7471ff3b02a44a8 to your computer and use it in GitHub Desktop.
const warn = @import("std").debug.warn;
fn Arr(comptime len: i32, comptime T: type) type {
var ty: [1]type = []type{void};
var i = len;
while (i > 0) : (i -= 1) {
var t = ty[0];
ty[0] = struct {head: T, tail: t};
}
return ty[0];
}
fn foo(comptime len: i32, a: Arr(len, i32)) %i32 {
return 3;
}
fn cons(comptime T: type, comptime len: i32, x: T, xs: Arr(len, T)) Arr(len + 1, T) {
return Arr(len + 1, T) {.head = x, .tail = xs};
}
test "foo" {
warn("{}\n", foo(1, cons(i32, 0, 3, {})));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment