Skip to content

Instantly share code, notes, and snippets.

@Wolf480pl
Created April 27, 2020 21:13
Show Gist options
  • Save Wolf480pl/9906ba96414a704e4914565167c34794 to your computer and use it in GitHub Desktop.
Save Wolf480pl/9906ba96414a704e4914565167c34794 to your computer and use it in GitHub Desktop.
const std = @import("std");
pub fn BoolOrNat(comptime b : bool) type {
if (b) {
return bool;
} else {
return usize;
}
}
pub fn trueOrOne(b : bool) BoolOrNat(b) {
if (b) {
return true;
} else {
return 1;
}
}
pub fn main() !void {
const b = trueOrOne(true);
const i = trueOrOne(false);
std.debug.warn("{} {}", .{b, i});
}
const std = @import("std");
pub fn BoolOrNat(comptime b : bool) type {
if (b) {
return bool;
} else {
return usize;
}
}
pub fn trueOrOne(comptime b : bool) BoolOrNat(b) {
if (b) {
return true;
} else {
return 1;
}
}
pub fn main() !void {
const b = trueOrOne(true);
const i = trueOrOne(false);
std.debug.warn("{} {}", .{b, i});
}
./deptypes.zig:12:38: error: use of undeclared identifier 'b'
pub fn trueOrOne(b : bool) BoolOrNat(b) {
^
./deptypes.zig:32:15: note: referenced here
const b = trueOrOne(true);
^
/usr/lib/zig/std/start.zig:253:40: note: referenced here
const result = root.main() catch |err| {
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment