-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A type for meaningless values (similar to unit type) #95
base: master
Are you sure you want to change the base?
Conversation
But why call it |
We can call it
That name does not exactly reflect what's going on because in runtime there actually may be any data. |
I like this. It seems unfortunate that we wind up with two types for the same thing in the stdlib though. |
In my mind that's true because it accepts |
I prefer either Noise or None. Noise is used by tink, while None is used by python (and I prefer it when making interpreters) |
I have used a lot of languages and when I came across 'unit' in ocaml, I was confused - so there will be some explaining to do because it is not obvious from its name. I think 'None' from python is better, although they tend to use this as a value rather than a type. I would also like to put forward the 'Empty' type - a variable with nothing in it, rather than a variable with the same (unit) thing in it that also takes 0 bytes. |
Agree that Unit is a non-obvious name, my first guess is that would be a type that has a value of Empty and None are clearer but synonymous with Void What about |
None is not synonymous with Void; |
That is not intuitively clear though. C developers are confused because they're familiar with |
Should this be a bottom type? Like Never in typescript or Nothing in scala or Void in haskell? |
If no, why not use a Unit type in such cases? |
Had a second look, this NoUse type is actually more similar to |
Not sure about the grammar or exact meaning of "NoUse" - I would prefer "DontUse", "NotUsed", "Useless" or "Unused" depending of what you are going for. |
|
I think erasing can be made to work - either by substituting In the template example, you would need to call something like The compiler could also infer |
i would really suggest taking a look at typescripts |
@frabbit Top and bottom types are different concepts, unrelated to unit types. Top types correspond to Haxe's |
@Aurel300 but the proposal says |
typescripts |
enum abstract NoUse(Null<Dynamic>) from Dynamic {
var NoUse = null;
}
class Test {
static function main() {
var x:NoUse = 1; //compiles fine
var x:NoUse = "hey"; //compiles fine
}
} |
isn’t that basically what tink noise is? |
@frabbit I agree with you here:
And we already have such a (top) type, it is called var x:Any = 1;
var y:Any = "hey"; So if you want to do this for signals or whatever you can already use I disagree with this proposal in two things:
enum abstract NoUse(Int) {
var NoUse = 0;
@:from static function fromDynamic(_:Dynamic):NoUse return NoUse;
} With the implementation in the proposal, even though the variable isn't accessible without casts, it remains part of the |
@Aurel300 I agree, my fear was that such a type was added and named Unit. Which is different ;). |
@Aurel300 The problem with your suggested implementation is that is doesn't solve the problems mentionend in the proposal because of variance. enum abstract NoUse(Int) {
var NoUse = 0;
@:from static function fromDynamic(_:Dynamic):NoUse return NoUse;
}
final f = () -> 1;
final g:() -> NoUse = f; // doesnt compile |
the |
Btw the name |
oh dear. runners up for me would be |
just an idea, maybe |
Throwing |
"Unit type" is far easier to google than any of the other suggestions if the name is a concern, but it's also not quite the same thing as what's being proposed here (for example I wouldn't want the unification stuff at all if it was really meant to be a Unit type) |
There are certainly some cases where unification is desired rather than converting everything here and there to However I also agree with this:
As it is not ideal that the If it is not possible to replace all values to a single one when casting to That said, what I personally wish is a super loose unification like the below (without runtime cost if possible), but I know this should be quite controversial. // Functions with Void/Any
var fnVoidBool:() -> Bool = () -> true;
var fnBoolVoid:Bool->Void = _ -> {};
var fnBoolAny:Bool->Any = v -> v;
var fnVoidVoid:() -> Void = () -> {};
// Void/Any to Noise
var fnNoiseBool:Noise->Bool = fnVoidBool;
var fnBoolNoise:Bool->Noise = fnBoolVoid;
var fnBoolNoise2:Bool->Noise = fnBoolAny;
var fnNoiseNoise:Noise->Noise = fnVoidVoid;
// Noise to Void
var fnVoidBool2:() -> Bool = fnNoiseBool;
var fnVoidVoid2:() -> Void = fnNoiseNoise; |
And regarding the name, I personally think:
|
Not sure if this discussion is ever going to get resolved, but this abstract did what I wanted it to. |
With Haxe 5.0, |
It seems the opposite, where |
Unlike
Void
, which implies no value at all,NoUse
type would allow to express a value with no meaning in places where a value has to exist.Rendered version