proposed @noreturn attribute

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sun Jul 9 03:48:30 PDT 2017


On 09.07.2017 07:44, Walter Bright wrote:
> On 7/8/2017 9:32 PM, Meta wrote:
>> On Sunday, 9 July 2017 at 04:23:15 UTC, Meta wrote:
>>> On Sunday, 9 July 2017 at 02:25:50 UTC, Walter Bright wrote:
>>>> (D already has a `void` type, so can't use Haskell's word.)
>>>
>>> Just so we are all on the same page, from a type-theory perspective 
>>> void is a unit type (it has 1 value), not an uninhabited type (it has 
>>> no values, i.e. Haskell's _|_ (bottom) type).
> 
> I read that a Void function in Haskell does not return. Is that 
> incorrect?

It is indeed incorrect, but this has little relevance for D. In Haskell, 
non-termination and exceptions are values that you can store in a 
variable (due to lazy evaluation). A function can return non-termination 
or exceptions non-evaluated. When those values are finally lazily 
evaluated, you get actual non-termination or a thrown exception. This is 
why Haskell has no empty type. If evaluation in Haskell was strict (as 
D's is), a function with return type Void would not be able to return. 
(BTW: it makes more sense to return a polymorphic value, i.e. x :: t 
instead of using the Void type, because Haskell does not have subtyping. 
This still implies that x does not contain a 'real' value, because we 
can instantiate t with Void.)

> I'm not sure how Void relates to _|_
> 
>    https://en.wikipedia.org/wiki/Bottom_type#In_programming_languages
> 
> says Haskell does not support empty (i.e. bottom) types.
> ...


More information about the Digitalmars-d mailing list