Created
June 24, 2014 03:16
-
-
Save betamatt/66819f6cbedc0cc7c352 to your computer and use it in GitHub Desktop.
Hacking around Swift's generics bugs
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
class Cell<T> { | |
let cell: T[] | |
var value: T { | |
get { return cell[0] } | |
} | |
init (_ value:T) { | |
self.cell = [value] | |
} | |
} | |
operator prefix * {} | |
@prefix func * <T> (c:Cell<T>) -> T | |
{ | |
return c.value | |
} | |
// Either type | |
enum Result<L,R> { | |
case Ok(Cell<L>) | |
case Err(Cell<R>) | |
static func ok(value:L) -> Result { | |
return Ok(Cell(value)) | |
} | |
static func right(value:R) -> Result { | |
return Err(Cell(value)) | |
} | |
} | |
let blah = Result<String, String>.ok("Blah!") | |
switch blah { | |
case .Ok(let x) : | |
*x | |
case .Err(let e) : | |
*e | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment