News for hackers. Stuff that matters.
Re:Bottom Type in F# by eithed on Wednesday September 23, 2020 @05:56AM (#24565076)
Could you please explain the difference between f: X -> void and f: X -> Bottom? If there was a void type in C, would void be Bottom?
Re:Bottom Type in F# by masklinn on Wednesday September 23, 2020 @06:12AM (#24565176)
Conceptually, void is a singleton type: it has one value. So a function which returns void does return, just without anything useful.

Bottom has no value, so a function which “returns” bottom can not terminate.

Practically, this means it either loops forever or “breaks” e.g. panics or exits the program.

Re:Bottom Type in F# by contravariant on Wednesday September 23, 2020 @06:16AM (#24565200)
No the Bottom type has no values, while the void type has exactly 1 (which doesn't have a name, but you can return it by writing `return;`).

So a function f: X -> void returns the only (nameless) value in void, depending on the programming language it will return null or equivalent or it'll just return no data (but it'll still return).

A function f: X -> Bottom is different, the type Bottom has no values so it is impossible for the function to ever return. This is not always useful, but in some strongly typed you need it to assign a value to an infinite loop.

Re:Bottom Type in F# by eithed on Wednesday September 23, 2020 @11:30AM (#24568209)
Oh, so you have the distinction between `function foo() { return; }` and `function bar() {}`. From the languages I'm accustomed to, yes, second syntax is first syntax under the hood.

Thanks for the explanation!

Re:Bottom Type in F# by masklinn on Wednesday September 23, 2020 @01:27PM (#24569578)
> Oh, so you have the distinction between `function foo() { return; }` and `function bar() {}`. From the languages I'm accustomed to, yes, second syntax is first syntax under the hood.

The second function terminates, same as the first one, there's no real difference between them.

A bottom-returning function would be something like

    function foo() { for(;;) {} }
that genuinely never terminates and thus never exits.