## The Forum for Discussion about The Third Manifesto and Related Matters

Forum breadcrumbs - You are here:
Please or Register to create posts and topics.

# Which Result?

Page 1 of 8Next

Over on another thread, Anthony said an important thing

In a programming language, a function/operator can return only one result. That result might be a pair or data structure with identifiable fields or components such that we might say loosely "more than one value". From the point of view of programming language semantics, that's one result at one type.   (Edit, I originally mis-corrected Anthony to "result and one type" as I thought it was a typo in the original,  I've now reverted my "correction")

Sure. This is how things work. But is it how things should work?

The answer to the question "What is the square root of 1", is not one answer but two.

Who wrote the third manifesto books? That has one answer, the set `{ "Chris Date", "Hugh Darwen" }`

but the "square root of 1" is not the set `{-1, 1}`. No. It is `-1` and it is `1`.  Two independent answers.  Sure we can collect them into a set called "the square roots of 1", but that set is not the answer to the question. It is the answer to the question, "what is the set of the square roots of 1"

Take another example. What is `1 + 1`?  The answer is `2` . It is not `{2}`. That would be the answer to the question "what is the set of the results of `1+1`"

A quadratic equation has two solutions. Yes you can put those solutions into a set, but fundamentally, the solution to a quadratic equation is two things, not one.

The same goes for empty. Empty is not a value, it is the absence of value. If the result is empty, there is not one result, there is no result.

Why, in that case, in all programming languages (that I am aware of at least) do function/operators only return one result?

Quote from Paul Vernon on November 15, 2021, 4:05 pm

Over on another thread, Anthony said an important thing

In a programming language, a function/operator can return only one result. That result might be a pair or data structure with identifiable fields or components such that we might say loosely "more than one value". From the point of view of programming language semantics, that's one result at and one type.

Sure. This is how things work. But is it how things should work?

The answer to the question "What is the square root of 1", is not one answer but two.

Who wrote the third manifesto books? That has one answer, the set `{ "Chris Date", "Hugh Darwen" }`

but the "square root of 1" is not the set `{-1, 1}`. No. It is `-1` and it is `1`.  Two independent answers.  Sure we can collect them into a set called "the square roots of 1", but that set is not the answer to the question. It is the answer to the question, "what is the set of the square roots of 1"

Take another example. What is `1 + 1`?  The answer is `2` . It is not `{2}`. That would be the answer to the question "what is the set of the results of `1+1`"

A quadratic equation has two solutions. Yes you can put those solutions into a set, but fundamentally, the solution to a quadratic equation is two things, not one.

The same goes for empty. Empty is not a value, it is the absence of value. If the result is empty, there is not one result, there is no result.

Why, in that case, in all programming languages (that I am aware of at least) do function/operators only return one result?

Restricting functions (or procedures) to returning a single value isn't a problem because the single value can be an array, vector, list, tuple, pair, relation, class instance, or whatever is most appropriate to contain the result.

In other words, there's nothing to stop your square root or quadratic equation operators from returning (say) a pair or an array. An array might contain two elements, or n elements, or one element, or none.

Thus, the "single" return value in popular programming languages is more about syntactic mechanics than a semantic limitation.

Quote from Paul Vernon on November 15, 2021, 4:05 pm

Over on another thread, Anthony said an important thing

In a programming language, a function/operator can return only one result. That result might be a pair or data structure with identifiable fields or components such that we might say loosely "more than one value". From the point of view of programming language semantics, that's one result at and one type.

That's a mis-correction: I said "one result at one type" because I mean one result at one type. And I don't mean there's two things (one result/value as opposed to one type) joined by "and".

Firstly, programmers often talk of 'value at type'; secondly I put it that way deliberately to counter you using phrases like 'value belongs to type' or 'type contains value', because it's leading you into all sorts of mis-conceptions. We don't talk of 'radius belongs to circle' or 'circle contains circumference', even if we say a circle is (defined as) a set of points.

OK. The use of the word "at" did confuse me. In fact, I'm still confused. "Value at type" is not a phrase I've seen before as far as I recall. Have you got a link or some other explanation of what it means? Why does the phrase "Value of some type" not suffice (although, I can see how that might be not satisfactory if a value is allowed to have more that one type)?

P.S. I'm not sure I've used the phrases  'value belongs to type' or 'type contains value'. A type is a set and a scalar value is a member of (at least one) such set. That is what TTM says, and I'm not sure I've said anything substantially different (or using substantially different phraseology). I just question the "at least one" bit - i.e. my position is that, yes a value can be the member of a set that you nominate as a type, but it does not have to. Values standalone and do not (even conceptually) carry with them some indication of their type.

Quote from Paul Vernon on November 15, 2021, 8:17 pm

...

Values standalone and do not (even conceptually) carry with them some indication of their type.

Then how do you know what operators can be applied to them?

Quote from Paul Vernon on November 15, 2021, 8:17 pm

OK. The use of the word "at" did confuse me. In fact, I'm still confused. "Value at type" is not a phrase I've seen before as far as I recall. Have you got a link or some other explanation of what it means?

Robert Harper being one of the gurus of programming type theory: exercise 14.6, q 2.

One of the wiki articles: section 'Subtyping schemes'.

Random dissertation: page 172.

Why does the phrase "Value of some type" not suffice (although, I can see how that might be not satisfactory if a value is allowed to have more that one type)?

There are a lot of loose phrases programmers (and program language manuals) use. I'm not pedantic about it, providing it's clear the speaker/writer understands types and programming languages. The arm-waving way you're going-on suggests you don't understand; and that you think types are somehow alienable from values (or v.v., I really can't be bothered to work out whether there's any coherence to your ramblings).

P.S. I'm not sure I've used the phrases  'value belongs to type' or 'type contains value'. A type is a set and a scalar value is a member of (at least one) such set. That is what TTM says, and I'm not sure I've said anything substantially different (or using substantially different phraseology). I just question the "at least one" bit - i.e. my position is that, yes a value can be the member of a set that you nominate as a type, but it does not have to. Values standalone and do not (even conceptually) carry with them some indication of their type.

TTM's type theory is not gospel; D&D are clear they've made a number of design choices for their purposes. Other design choices are equally valid. A value not being at some type is not amongst the design choices for programming languages. Have you got a link for such a programming language?

When we're writing programs, we don't write them to manipulate a single 'standalone' value. We write them to manipulate (add, test for equality, lookup, display) values (plural) with some characteristic quality -- usually different characteristics in different syntactic positions in the program text. A program to `print "hello world";` is not an example of 'programming' -- even if a programming tutorial begins with something like that.

As @Dave keeps telling you, every programming language comes with a mechanism to put values at types, even if the programmer has to do all the hard yards themselves maintaining type hygiene.

Quote from Paul Vernon on November 15, 2021, 4:05 pm

Over on another thread, Anthony said an important thing

In a programming language, a function/operator can return only one result. That result might be a pair or data structure with identifiable fields or components such that we might say loosely "more than one value". From the point of view of programming language semantics, that's one result at one type.   (Edit, I originally mis-corrected Anthony to "result and one type" as I thought it was a typo in the original,  I've now reverted my "correction")

Sure. This is how things work. But is it how things should work?

The answer to the question "What is the square root of 1", is not one answer but two.

Who wrote the third manifesto books? That has one answer, the set `{ "Chris Date", "Hugh Darwen" }`

but the "square root of 1" is not the set `{-1, 1}`. No. It is `-1` and it is `1`.  Two independent answers.  Sure we can collect them into a set called "the square roots of 1", but that set is not the answer to the question. It is the answer to the question, "what is the set of the square roots of 1"

Take another example. What is `1 + 1`?  The answer is `2` . It is not `{2}`. That would be the answer to the question "what is the set of the results of `1+1`"

A quadratic equation has two solutions. Yes you can put those solutions into a set, but fundamentally, the solution to a quadratic equation is two things, not one.

The same goes for empty. Empty is not a value, it is the absence of value. If the result is empty, there is not one result, there is no result.

Why, in that case, in all programming languages (that I am aware of at least) do function/operators only return one result?

Many of the questions you ask have one extremely simple answer: because they're defined that way. Why is 'yellow' the name of a particular colour? Because it's defined that way.

Functions return one value, for zero or more arguments. There is no function that returns two arguments, or none. It's defined that way. [But of course that single result could be a set or list or anything, really. And there are definitions around that too: range and domain.]

"What is the square root of 1" is vague English, and can be interpreted in several ways:

• What is the set of values that satisfies the equation x^2=y (x and y real)? Depending on y the answer is a set of 0, 1, or 2 values.
• What is the value returned by sqrt(1) in a typical programming language? Answer: 1. The function must not be applied to negative arguments.
• And so on.

I find some of your questions lacking in clear definitions. They would be trivial to answer, if they were well-defined in the asking.

Andl - A New Database Language - andl.org
Quote from AntC on November 15, 2021, 11:10 pm
Quote from Paul Vernon on November 15, 2021, 8:17 pm

OK. The use of the word "at" did confuse me. In fact, I'm still confused. "Value at type" is not a phrase I've seen before as far as I recall. Have you got a link or some other explanation of what it means?

Robert Harper being one of the gurus of programming type theory: exercise 14.6, q 2.

One of the wiki articles: section 'Subtyping schemes'.

Random dissertation: page 172.

Thank you Anthony.

One of my reasons for posting to the forum is to help me understand what terminology, phraseology etc works best for exploring and explaining my ideas.

The "value at type", I can see is useful when a type system has sub-typing. I had found the sentence in your 2nd link above , but it was not immediate obvious (to me) quite what the meaning was. On re-reading it:

Implementations of programming languages with subtyping fall into two general classes: inclusive implementations, in which the representation of any value of type A also represents the same value at type B if A <: B

I can see that value at type is the situation where, e.g the value `2` is held in an variable of type `INTEGER` and so can be said to be "2 at integer" (or "2 at type integer"); and then if the value `2` is held in a variable of type `RATIONAL` it can be said to be "2 at rational".  Generically then this idea is known as "value at type", and it does not apply only to values in variables, but also to functions/operators whose input/output also have "at types" and return values "at a" specified type.

That is all good and fine. I might ask, can a value that is neither in a variable, nor being currently used as the input to, or being generated as the result of some function, be said to be "at type". I.e. `2::INTEGER` is "2 at Integer", and `2::RATIONAL`. I assume yes. If so, then is it possible to have the value `2` on its own?  If so, I would think it must be a shorthand. Either for "2 at" some nominated default type for that value.  Say "2 at Natural", "2 at Prime", or whatever was (contextually) picked at the default,  or be short for a value independent "at" construct - specifically either "2 at 2" or "2 at alpha". I would be interested to know if programming languages are consistent here.

My only further comment would be, that if you are a Wikipedia contributor, then maybe consider creating a value at type page, or consider changing the above to define the "at" usage explicitly (e.g. say "this is known as 'value A being at type B`") , rather than implicitly via the sentence as is.  Even just putting the word "at" in bold on the exiting page would be help.

Quote from Dave Voorhis on November 15, 2021, 10:26 pm
Quote from Paul Vernon on November 15, 2021, 8:17 pm

...

Values standalone and do not (even conceptually) carry with them some indication of their type.

Then how do you know what operators can be applied to them?

I would join my value(s) into the set of all function relations then project the function names.

( ask me a difficult one 😀 )

Quote from Paul Vernon on November 16, 2021, 12:24 pm
Quote from Dave Voorhis on November 15, 2021, 10:26 pm
Quote from Paul Vernon on November 15, 2021, 8:17 pm

...

Values standalone and do not (even conceptually) carry with them some indication of their type.

Then how do you know what operators can be applied to them?

I would join my value(s) into the set of all function relations then project the function names.

So in other words...

...you'd create a type definition! :-)

Now if you're saying every operator applies to every value (type), then you're effectively implementing the semantics of your type system within the operators themselves. That's fine; a given numeric operator can (for example) distinguish operands with all digits (i.e., an integer) from operands with a decimal point (i.e., a decimal number) from operands with zero or more digits followed by non-digits (i.e., a string.)

Some languages work that way.

Alternatively, you can leave it to your users to know -- based on reading and understanding the code -- whether a given operand is (for example) an integer, or a decimal number, or a string and choose the right operator(s) for the circumstances.

Other languages work that way. (FORTH and most machine/assembly languages being notable examples.)