Skip to content

Instantly share code, notes, and snippets.

@ukitaka
Last active October 1, 2018 02:57
Show Gist options
  • Save ukitaka/7732fe1afc5728efb9a13c994216e750 to your computer and use it in GitHub Desktop.
Save ukitaka/7732fe1afc5728efb9a13c994216e750 to your computer and use it in GitHub Desktop.
indirect+loe.swift
func update<T>(value: inout T, update: (inout T) -> Void) {
update(&value)
}
struct Hoge {
var list: List<Int>
}
enum List<T> {
case `nil`
indirect case cons(T, List<T>)
}
var hoge = Hoge(list: List.cons(1, .cons(2, .nil)))
update(value: &hoge) { h in
let list = h.list
// Simultaneous accesses to 0x10b087578, but modification requires exclusive access.
h.list = List.cons(10, list)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment