Timeline for Declaring that a function never returns
Current License: CC BY-SA 4.0
20 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 25, 2020 at 18:32 | audit | First posts | |||
Aug 25, 2020 at 18:32 | |||||
Aug 25, 2020 at 11:35 | comment | added | HTNW | @occipita Java also has a built-in null type, it's just not nameable. See the JLS. Void is an ordinary class that can't be constructed, so it has no objects and the reference type is thus a singleton (containing only null). | |
Aug 25, 2020 at 4:08 | comment | added | occipita |
@HTNW - Java/Scala, the Null type (which is unnamed in Java) contains only the value null ... in Java the appropriate type with this property is java.lang.Void .
|
|
Aug 21, 2020 at 18:14 | comment | added | Joshua |
I miss the old way of doing it in C. You wrote volatile void and the compiler understood the nonsensical type to be uninhabitable and therefore the function never returned.
|
|
Aug 21, 2020 at 10:34 | comment | added | Steve |
@AlexanderReinstateMonica, what I'm more particularly curious about is whether () (arity 0) is equivalent to (NULL) (arity 1), where the type of the single value of the latter is the Null type. Or is that considered to be a degenerate case where both are equivalent? My own understanding is not complete in this area, but straight away I can see that there's room for trouble - there would appear to be a structural distinction, even if there is no distinction of values carried.
|
|
Aug 21, 2020 at 10:25 | comment | added | Steve |
@HTNW, it was only an offhand thought, but can you think of a situation not covered by "jump"? These "jump types" (i.e. "bottom", "never" or "noreturn" types) are a way of expressing what is essentially the functional equivalent of the GOTO - an unstructured deviation from the normal linear call-and-return pattern. "Jump" also seems to be a long-accepted and well-understood terminology for the concept.
|
|
Aug 20, 2020 at 18:29 | comment | added | Alexander |
@Steve Yes, Void is the same concept of null and unit. It's a type with only one valid value (the empty tuple () , unit , null , etc.). For languages with nullable-by-default (e.g. Java) references, each such reference can point to either an object of T , or null (which could be thought of as the only possible instance of an imaginary Null type. You can imagine that each T actually means T | Null . A consequence of this is that a truly-non instantiatiable Never isn't possible, since null is allowed everywhere. See docs.oracle.com/javase/7/docs/api/java/lang/Void.html
|
|
Aug 20, 2020 at 8:48 | comment | added | Luaan | @Fred A big difference is that in languages like Haskell, not using a return value is the exception; you must do it explicitly, or you get compiler warnings/errors. In languages like C or C#, you ignore return values quite often and implicitly (though C# is certainly getting more functional with every new release). Of course, ignoring the return value is very common source of programming errors, which led to both the introduction of exceptions (instead of returning error values) C-like languages and the requirement to handle all return values in ML-like languages. | |
Aug 20, 2020 at 4:35 | comment | added | WorldSEnder | One relevant attribute for c# can be found in stackoverflow.com/a/59582675/3102935 | |
S Aug 20, 2020 at 0:40 | history | suggested | Bergi | CC BY-SA 4.0 |
The name that escaped you :-)
|
Aug 20, 2020 at 0:39 | comment | added | Jörg W Mittag | @Steve: there is standardization, mostly. Both the type and the value for a function that returns no useful value is almost universally called unit. It is only a small number of languages that deviate from that and call it void. Although note that the concept of void in e.g. C is very different, because it is not actually a type, it is more of a marker. In particular, in languages like Scala, there are no statements, there are only expressions. What would be a statement in C or Java is still an expression in Scala, just one whose value is unit. | |
Aug 20, 2020 at 0:26 | comment | added | benrg |
I don't think Void is ever used to mark a function that doesn't return in Haskell. The normal way to do it is forall a. a , which is also what will be inferred for the return type if you don't give a type signature. (Since a pure function that doesn't return is pointless, it'd be more likely to be forall a. IO a .)
|
|
Aug 19, 2020 at 22:39 | comment | added | HTNW |
Haskell's is called Void . A fairly standard name is "empty type", which doesn't imply subtyping like "bottom type". C (and friends)'s void can be seen as having a single value (therefore no information; if you know something is void you know its value), that you just can't name. The identity of that single value is not important. In Java/Scala, the Null type (which is unnamed in Java) contains only the value null , but it's different from Scala's Unit , which has a different singleton value. "Jump type" seems... too specific? Maybe "unreachable".
|
|
Aug 19, 2020 at 22:09 | review | Suggested edits | |||
S Aug 20, 2020 at 0:40 | |||||
Aug 19, 2020 at 16:03 | comment | added | Steve | @JörgWMittag, I only wish there could be standardisation of these terms. Void is pretty widely understood - it means the method returns without any value. But is that the same concept as Null? And practically speaking, a "never" type is probably better called the jump type or something similar - you're either going to jump up the stack in an unstructured fashion (for example with an exception), or jump out of the program completely (for example with an exit statement that terminates the process). It all gets very confusing. | |
Aug 19, 2020 at 15:05 | comment | added | Jörg W Mittag |
@Fred: void signifies that a function does return, but doesn't return a useful value. never signifies that a function doesn't return. The equivalent to void in a more expressive type system would be a unit type, i.e. a type which has only one instance and no useful operations.
|
|
Aug 19, 2020 at 14:21 | comment | added | 8bittree |
@Fred void at least in C, C++, and many similar languages just means the function doesn't return a value, but provides no indication on whether or not the function actually returns. A bottom type is a type that cannot be instantiated. A function that returns a bottom type cannot return without providing an instance of the bottom type, but since bottom cannot be instantiated, it must diverge, i.e. loop forever, throw an exception, power off the machine, etc.
|
|
Aug 19, 2020 at 14:08 | comment | added | Fred |
How is never and Nothing different from void ? Can these never and Nothing return types indicate that the function runs indefinitely in an infinite loop and never yields control back to where it was called from?
|
|
Aug 19, 2020 at 13:42 | comment | added | Andy | Yes, for most languages, documentation, convention and consistency should be the way how to "solve" this (e.g. by using a specific method suffix). For other languages actually supporting a mechanism to represent a method which never terminates, such mechanism should be used. | |
Aug 19, 2020 at 13:39 | history | answered | Jörg W Mittag | CC BY-SA 4.0 |