Last active
September 28, 2015 10:34
-
-
Save jepers/cb72b7f5432e80130281 to your computer and use it in GitHub Desktop.
A compile time / type level NAND "function" in Swift.
This file contains hidden or 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
protocol Bit {} | |
protocol IsSet {} | |
protocol IsClr {} | |
struct Set : Bit, IsSet {} | |
struct Clr : Bit, IsClr {} | |
protocol NandOp { typealias Result } | |
extension NandOp { typealias Result = Set } | |
struct Nand<B0: Bit, B1: Bit> : NandOp {} | |
extension Nand where B0: IsSet, B1: IsSet { | |
typealias Result = Clr | |
} | |
print(Nand<Clr, Clr>.Result.self == Set.self) // true | |
print(Nand<Clr, Set>.Result.self == Set.self) // true | |
print(Nand<Set, Clr>.Result.self == Set.self) // true | |
print(Nand<Set, Set>.Result.self == Clr.self) // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bummer:
:´ (