Last active
August 29, 2015 14:14
-
-
Save austinzheng/1046881428740b7d3029 to your computer and use it in GitHub Desktop.
generics deadlock example
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
import Foundation | |
// Build this as an OS X command line project, then run it. It should never terminate. | |
enum Value<T> { | |
case Nil | |
case Cons(T, LinkedList<T>) | |
} | |
final class LinkedList<T> { | |
let value : Value<T> | |
// Build the empty list | |
init() { | |
value = .Nil | |
} | |
// Build a list with only one item | |
init(_ item: T) { | |
value = .Cons(item, LinkedList()) | |
} | |
// Build a list by adding an item to an existing list | |
init(_ item: T, next: LinkedList<T>) { | |
value = .Cons(item, next) | |
} | |
} | |
func main() { | |
println("Starting...") | |
// let myList : LinkedList<Int> = LinkedList(15, next: LinkedList(20, next: LinkedList(18))) | |
let myList : LinkedList<String> = LinkedList("hello") | |
println("Finished...") | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment