-
Notifications
You must be signed in to change notification settings - Fork 452
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
Source of truth for standard library types #7126
Comments
For null and undefined, Core -> Js -> Primitive |
My theory here is that
|
The way I perceive it is that
|
The way I prototyped it in https://github.com/rescript-lang/experimental-rescript-stdlib-build/blob/main/runtime/src/runtime_types.res, I had Core -> Runtime_types |
Another question is the module name, if any. Should it be |
Same question for the existing built in types. |
Js maps are not transparent in their implementation. I would never recommend treating them as primitives. |
It would certainly be nice to have |
As I mentioned in Discord before, Array and list structures are simple and predictable, but map/set have much wider use cases. Whether it is a tree or a hashtable should be determined at the call site, and the only thing that the build depends on is the abstract type. Dict is something that we already had in other forms. Symbol is a primitive type in JS, so it is worth considering, but RegExp is just an Object with a different prototype. IMHO we have to be very careful when choosing these. Treating something that isn't primitive as if it were a primitive is a decision we can never reverse. And it limits the quality of the implementation beyond just the interface. |
Do you think Belt is no longer needed once Core bindings are provided? In fact, there are examples where Belt Map works more efficiently than Js Map. https://github.com/cometkim/benchmark-rescript-cache-impl We don't have to specify the properties of implementations in the language, even if Js does. I keep emphasizing the different responsibilities of primitives and stdlib. |
I disagree that it should be the reason not to include the |
I am not against adding widely used utilities to the standard library. However, "widely used" does not imply the existence of primitives. Primitives are the most fundamental part of a language and have a lasting impact on subsequent designs. Beyond simply declaring built-in types, they interact with other features of the language, adding complexity and side effects of its semantic. Even with poorly designed one, they are more cumbersome to work with and lower the average quality of software written in ReScript. Especially There are reasons why stuffs like |
If pattern match is possible for arbitrary constructors like |
If we support Date more conveniently because it already exists, then that is literally why people use Date. Because it is better supported, users avoid better alternatives than Date, even if they are standards driven. This is exactly what happened between CommonJS and ESM. ESM offers a better future, but CommonJS didn't switch simply because it was work and advanced use cases. The interoperability story is not simple, because the two specifications have distinctly different semantics. The same thing probably happens between Date and Temporal. |
I was not saying that we need to make date and regExp built-in types (as in https://github.com/rescript-lang/rescript-compiler/blob/master/compiler/ml/predef.ml) and implement pattern matching for them. This is just about the fact that the "source of truth" cannot stay in the The easiest solution without any additional modules or circular dependencies: Date.res: type t Js_date.res: type t = Js.Date.t and, for convenience, Pervasives.res: type date = Date.t Also not saying that we necessarily need to have aliases for Map.t and Set.t in Pervasives. When Temporal is added later, I see no harm in having both type date = Date.t
type temporal = Temporal.t in Pervasives. |
This sounds like the best decision to me. I know it's not what you meant @cknitt , but just for the record, I think @cometkim has a good point about what to make builtins and not (which I also think we all agree on already). But just aliasing is fine. |
Nit: I would just not use the term `builtin` here, but something like types
belonging to the language rather than to a library (and presented
accordingly in the documentation). Whether internally they are implemented
as builtin is an implementation detail.
…On Fri, Oct 25, 2024 at 8:02 AM Gabriel Nordeborn ***@***.***> wrote:
I was not saying that we need to make date and regExp built-in types (as
in
https://github.com/rescript-lang/rescript-compiler/blob/master/compiler/ml/predef.ml)
and implement pattern matching for them.
This is just about the fact that the "source of truth" cannot stay in the
Js modules as these are legacy modules that will eventually be moved out
to some compatibility package, and we need to decide where to put them
instead.
The easiest solution without any additional modules or circular
dependencies:
Date.res:
type t
Js_date.res:
type t = Js.Date.t
and, for convenience, Pervasives.res:
type date = Date.t
Also *not* saying that we necessarily need to have aliases for Map.t and
Set.t in Pervasives.
When Temporal is added later, I see no harm in having both
type date = Date.ttype temporal = Temporal.t
in Pervasives.
This sounds like the best decision to me. I know it's not what you meant
@cknitt <https://github.com/cknitt> , but just for the record, I think
@cometkim <https://github.com/cometkim> has a good point about what to
make *builtins* and not (which I also think we all agree on already). But
just aliasing is fine.
—
Reply to this email directly, view it on GitHub
<#7126 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB4YVF4TXVARTATGLAR2IPLZ5HNGDAVCNFSM6AAAAABQRA5R6SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMZWHEYTENZVG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
The important difference, I think, is whether it is treated as something the compiler can depend on. |
There are exceptions to this though. Regexp and Date are already special cased in unboxed variants, when though they're not defined in the compiler per se. |
That's the concern. Some things go beyond declaring types and going to be deeply integrated into the compiler. |
I had the same thought when moving What does that translate to if we support WASM targets in the future? I'm not trying to expand the topic we're discussing now, but it's about the direction it could take as we design the language. |
There is a problem with this approach though. If my project also has a
(BTW notice that this error message refers to the non-existing path
So it might be better if those types were defined in a different file with a name less likely to occur in user projects. |
This way works fine for me: 5828460 |
Currently we have e.g. in (Core) Map.res:
or in (Core) Null.res:
i.e., the
Js
modules are the source of truth.This should be changed, as
Js
should be deprecated.Two options:
Any opinions @cristianoc @zth @cometkim?
The text was updated successfully, but these errors were encountered: