Created
April 27, 2020 21:13
-
-
Save Wolf480pl/9906ba96414a704e4914565167c34794 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./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