Bottom Type--Type Theory

Neia Neutuladh neia at ikeran.org
Thu Jan 17 17:48:22 UTC 2019


On Thu, 17 Jan 2019 13:20:20 +0000, Olivier FAURE wrote:
> Actually, I think I have a pretty good question. Let's imagine we
> implement two types in D, Unit and Top, so that they match their type
> theory concepts as best as they can.
> 
> Given this code:
> 
>      int foo(Unit u) {
>          ...
>      }
> 
>      int bar(Top t) {
>          ...
>      }
> 
> what could you do in `bar` that you couldn't do in `foo`?

bar knows nothing about the value passed in. It's pretty much equivalent 
to taking a Variant. Or, if you're only dealing with OOP, it's like taking 
Object. It could do anything with that value, but it has to figure out 
what type it's dealing with first, then down-cast it.

foo knows the exact value that will be passed to it because there's only 
one possibility. It can't do anything with that value at runtime that it 
couldn't do at compile-time, so the whole function could be reduced to a 
constant (assuming it's pure), or the argument could be omitted. Kind of 
like taking a CheckedInt where min and max are both 0.


More information about the Digitalmars-d mailing list