-
-
Save jckarter/019f317b669961add5a3 to your computer and use it in GitHub Desktop.
matching tuple value
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
protocol Consable { | |
typealias Tuple | |
} | |
struct HCons<T, U: Consable>: Consable { | |
typealias Tuple = (T, U.Tuple) | |
} | |
struct HNil: Consable { | |
typealias Tuple = () | |
} | |
func ~=<T: Consable>(a: T.Tuple, b: T) -> Bool { | |
return true | |
} | |
func id<T>(x: T) -> T { return x } | |
switch (HCons<Int, HCons<Float, HNil>>()) { | |
// Need 'id' to trick compiler into thinking this is an expr pattern, not a tuple pattern | |
case id(1, (2.0, ())): | |
println("ok") | |
default: fatalError() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment