|
|
|
|
|
by theseoafs
3342 days ago
|
|
Depends on the implementation of the language. In a typical functional language with linear types, the functions that mutate an object return a "new value" that is conceptually a modified version of the first value. So fleshing out our example: open : () -> File
close : File -> ()
write : (File, String) -> File
let f: File = open()
let new_f : File = write(f, "Hello world!\n")
close(new_f)
If this seems clumsy or error-prone, notice that you can't accidentally close() f instead of new_f, and you can't forget to close() new_f, so there is actually very little room for error here. |
|