Hacker News new | ask | show | jobs
by drb91 2879 days ago
Most languages I can think of have this type, from void* to dyn to bounding by the root of the type hierarchy. Not all languages. However, what is c, c++, java, rust, go, if not statically typed? Ambiguously typed? Seems like not a useful distinction to make.

I argue static typing is the ability to static type up to 100% of a program, not the exclusion of a dynamic type.

1 comments

Rust doesn't have such type. And type annotations in Dart are optional - when programmers are not obliged to use them, guess what will happen? They do NOT use them. People are lazy.

Dart's types exist only on compilation step. You can try to use "strong mode" in theory, in practice you will never compile it with third-party libraries.

> And type annotations in Dart are optional - when programmers are not obliged to use them, guess what will happen?

The type system will infer a static type based on the type of the initializer.

In some cases, inference may fail to infer a type. Right now, that can silently give you dynamic, but there's a flag to make that an error. I expect before too long that will be the default behavior.

Rust has both raw void* pointers (within unsafe code) and the safe std::any::Any trait: https://doc.rust-lang.org/std/any/trait.Any.html
Trait is not a type, Any is just a custom trait. Types: https://doc.rust-lang.org/book/second-edition/ch03-02-data-t... You can create trait with name "Magic" or "Fuck" and it will not mean anything. Pointers is not a type also.
Ok, type bound. You can still easily pass around data whose type is not concretely defined at the compilation step. Unless you’re arguing that the dynamic type is actually static, in which case this whole conversation seems semantically pointless.
2 hours ago I answered it already. If you're another person who wants to convince me that Rust has same thing as Dart's "dynamic" type, then please make my code example to compile (without modifications, for literally ANY type, as in Dart) and I will say I was wrong.
Dart type or rust type? They refer to different things, which is the source of the confusion, but they're both strongly typed.

In any case, you're moving the goal post from "concrete type at compile time" to "can represent any type", which is inherently going to be specific to how the language defines types. This is not an especially useful type of dynamic representation so I'm not sure why it would be desirable.

Pointers are certainly types in Rust, and although it's of course true that the Any trait is not itself a type, a reference to an Any trait (which is what you'd actually pass around) is a type.
Well, you can repeat it many times but it will not become true. I gave you link to the list of Rust types. Pointers are pointers, not types. Traits can have any name, their names mean nothing.
https://doc.rust-lang.org/book/first-edition/raw-pointers.ht...

    *const u32
(for example) is a clearly a Rust type -- a const pointer to an unsigned 32-bit integer, analogous to

    const uint32_t *p
in C/C++.

I'm not sure what you mean about trait names. The purpose of the Any trait is to make it possible to pass around values of any type and dynamically downcast them, as the documentation indicates. That is a safe analogue of casting a void pointer to another type.

A pointer is absolutely a type in rust.

let i: u32 = 1;

let p_imm: const u32 = &i;

Look at the const u32 in the type position.

The rust book even refers to const and mut pointers as types.

const and mut are not types, it's modifiers of mutability. On both lines type is u32z
The asterisks in leshow's comment are being lost in the formatting, since HN uses them for italicization. So the last line, for example, is:

    The rust book even refers to *const and *mut pointers as types.
The asterisk was formatted out. Read the book, they are types.
Dart isn’t statically typed, at least not in the times i’ve used it; it’s gradually typed.
It was optionally typed. Dart 2 is statically typed.