The Introduction section describes Uniqueness, but I'm left wondering what the benefit of the extra complexity is. Regards, Ben Aveling 09:16, 7 September 2008
| This article is rated Start-class on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | ||||||||||||||||||
| ||||||||||||||||||
The Introduction section describes Uniqueness, but I'm left wondering what the benefit of the extra complexity is. Regards, Ben Aveling 09:16, 7 September 2008 (UTC)
I think that the introduction example is based on a conceptual error. Referential transparency means that f(x) should return the same value as long as x has the same value. In the case of an object, this could be reworded "x is in the same state". In the example:
function readLine(File f) returns String
the parameter is a 'File'. We are thus tempted to consider f the same way we consider files on a disk, or inside a file system: they are stable packs of data as long as not explicitely changed. But a 'File' in a programming language is instead a purely abstract representation of a real file that provides the information and references the programmer needs to operate on the real file via the OS.
Concretely, a File object holds a pointer attribute that tells where we currently are inside the file. (Actually, the OS representaton of a file also holds it, but we forget it when we think at a file on a disk.) So that consecutive calls to readLine above will not pass the same object/value, f will be each time in a different state: and consistently the function will not return the same value.
To make this explicit, just change the function definition to:
function readLine(DiskFile f, Integer pointer) returns String
or to
function readLine(PointedFile f) returns String
Imo, both of these formulations make it clear that readLine actually is referentially transparent.
--Denispir (talk) 09:58, 20 February 2009 (UTC)
function readLine2(unique File f) returns (File, String). Note how a new File is returned to account for the change of state. The file abstraction is standard in programming languages. No need to give it a more obtuse name. --Cybercobra (talk) 18:28, 20 February 2009 (UTC)I think the current text is incomprehensible. It should be expanded to a more comprehensible form, for instance via an example. The current text is the following:
A unique type is very similar to a linear type, to the point that the terms are often used interchangeably, but there is in fact a distinction: actual linear typing allows a non-linear value to be typecast to a linear form, while still retaining multiple references to it. Uniqueness guarantees that a value has no other references to it, while linearity guarantees that no more references can be made to a value. — Preceding unsigned comment added by Andreasabel (talk • contribs) 14:45, 19 February 2018 (UTC)
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.