3 ms·
FTA: In the April blog post, I mentioned I needed a way to write type and namespace aliases, and that because all Cpp2 declarations are of the form thing : type
by Someone 3y ago
FTA: In the April blog post, I mentioned I needed a way to write type and namespace aliases, and that because all Cpp2 declarations are of the form thing : type = value, I decided to try using the same syntax but with == to denote “always equal to.”
So, I think we have
// new type
foo = std::vector<int>;
// alias of existing type
bar == std::vector<int>;
I guess that could evolve to (or maybe already has evolved to?)
// variable with initial value
foo: int = 42;
// constant
bar: int == 42;
- naruhodo 3y agoOh... so the new type, foo, is distinct (not assignment-compatible) from std::vector<int>?
- Someone 3y agoYes, but functionally identical. See for example Haskell type vs new type: https://typeclasses.com/coerce https://typeclasses.com/coerce Python NewType: https://docs.python.org/3/library/typing.html#newtype https://docs.python.org/3/library/typing.html#newtype