Skip to content

Instantly share code, notes, and snippets.

@austinzheng
Last active August 29, 2015 14:14
Show Gist options
  • Save austinzheng/1046881428740b7d3029 to your computer and use it in GitHub Desktop.
Save austinzheng/1046881428740b7d3029 to your computer and use it in GitHub Desktop.
generics deadlock example
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