Last active
October 1, 2018 02:57
-
-
Save ukitaka/7732fe1afc5728efb9a13c994216e750 to your computer and use it in GitHub Desktop.
indirect+loe.swift
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
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