What are you talking about? If the compiled file extension, then as I know they inherit the file extension from the root bsconfig.
basically, it would be nice to use the file extension required in the dependency’s bsconfig instead of the root
Hi Yall
A following question from other threads:
Will explicit currying apply to Functors as well?
I cant say I hit it often, but when you dont fully saturate a functor, the warning is really something.
Thanks
A
Hi !
I started the migration and the watch seems to doesn’t work when I have code error. Any idea ?
Just in case, here is one of my rescript.json file config :
{
"$schema": "https://raw.githubusercontent.com/rescript-lang/rescript-compiler/master/docs/docson/build-schema.json",
"name": "@colisweb/rescript-toolkit",
"jsx": {
"version": 4
},
"sources": [
{
"dir": "src",
"subdirs": true
},
{
"dir": "playground",
"subdirs": true,
"type": "dev"
}
],
"package-specs": [
{
"module": "es6-global",
"in-source": false
}
],
"suffix": ".bs.js",
"namespace": false,
"uncurried": true,
"bs-dependencies": [
"@rescript/react",
"reason-promise",
"@greenlabs/ppx-spice",
"rescript-classnames",
"rescript-react-update",
"@dck/restorative"
],
"ppx-flags": [
["@greenlabs/ppx-spice/ppx", "-uncurried"],
"lenses-ppx/ppx",
"res-react-intl/ppx"
],
"warnings": {
"number": "-44-30-32",
"error": "+5"
},
"bsc-flags": [
"-bs-super-errors",
"-bs-no-version-header",
"-open Belt",
"-open Cx"
]
}
It’s a regression of rc-4
. I’ll fix it in the next version Watch mode is not working in `11.0.0-rc.4` · Issue #6435 · rescript-lang/rescript-compiler · GitHub.
As a solution you can try using rewatch.
Thanks for your fast reply !
I have some issues with Js.Dict.t
and the uncurried mode. I’m trying to upgrade the code based on this coupled with @spice
.
For reference, here is the implementation :
module MakeString = () => {
module Id: {
@spice
type t
module Dict: {
type key = t
@spice
type t<'a>
let get: (t<'a>, key) => option<'a>
@set_index
external set: (t<'a>, key, 'a) => unit = ""
@val
external keys: t<'a> => array<string> = "Object.keys"
@obj /** Returns an empty dictionary. */
external empty: unit => t<'a> = ""
let unsafeDeleteKey: (t<string>, string) => unit
let entries: t<'a> => array<(key, 'a)>
let values: t<'a> => array<'a>
let fromList: list<(key, 'a)> => t<'a>
let fromArray: array<(key, 'a)> => t<'a>
let map: ('a => 'b, t<'a>) => t<'b>
let deleteKey: (t<'a>, key) => t<'a>
}
} = {
@spice
type t = string
module Dict = {
include Js.Dict
let deleteKey: (t<'a>, string) => t<'a> = %raw("function (dict, key) {
const newDict = Object.assign({},dict);
delete newDict[key];
return newDict;
}")
let t_encode = (encoder, dict): Js.Json.t => Js.Json.Object(
Js.Dict.map(a => encoder(a), dict),
)
let t_decode = (decoder, json) => {
open Spice
switch (json: Js.Json.t) {
| Js.Json.Object(dict) =>
dict
->Js.Dict.entries
->Belt.Array.reduce(Ok(Js.Dict.empty()), (acc, (key, value)) =>
switch (acc, decoder(value)) {
| (Error(_), _) => acc
| (_, Error({path} as error)) => Error({...error, path: "." ++ (key ++ path)})
| (Ok(prev), Ok(newVal)) =>
let () = prev->Js.Dict.set(key, newVal)
Ok(prev)
}
)
| _ => Error({path: "", message: "Not a dict", value: json})
}
}
}
}
@spice
type t = Id.t
module Dict = Id.Dict
external make: string => t = "%identity"
external toString: t => string = "%identity"
}
The compiler complains about signature missmatch for the t_encode
function
Signature mismatch:
...
In module Dict:
Values do not match:
let t_encode: ('a => Js.Json.t, Js.Dict.t<'a>) => Js.Json.t
is not included in
let t_encode: ('a => Js.Json.t) => t<'a> => Js.Json.t
How could I handle this case ? I tried the dot notation but without success
Thanks again !
Isn’t it just a matter of following the signature and manually curry the function now that there’s no auto-currying?
let t_encode = (encoder) => (dict) => Js.Json.Object(...)
I tried but still get this fun missmatch
Signature mismatch:
...
In module Dict:
Values do not match:
let t_encode: ('a => Js.Json.t) => t<'a> => Js.Json.t
is not included in
let t_encode: ('a => Js.Json.t) => t<'a> => Js.Json.t
well well well that’s a known issue here, long story short, there’s a bug in how the compiler displays the error and I haven’t been able to solve it yet, but meanwhile anyway, to fix the error in itself, you’d better use RescriptCore.Dict
instead of Js
.
Running rescript build -w
with a compilation error exits with an error code, and I need to manually re-run it after every change until I get it to pass. Once passing, it goes back to restarting properly
I’ve just created it Fix watch exiting on error by DZakh · Pull Request #6460 · rescript-lang/rescript-compiler · GitHub
Something has changed about @deriving(jsConverter)
?
This code works well on v10.x
It likely generates curried functions which don’t work in uncurried mode.
Oh I didn’t thought about that ! Thanks !
We just merged a fix to make the error message clearer btw
I encountered a runtime error while migrating from ReScript version 10 to version 11, specifically with the use of uncurried functions. The issue is demonstrated in the following code snippet:
let fn = (a, b, ()) => a() + b
let a = fn(() => 1, 2, _)
When this ReScript code is compiled, it generates the following JavaScript:
// Generated by ReScript, PLEASE EDIT WITH CARE
function fn(a, b, param) {
return a() + b | 0;
}
function a() {
return fn((function () {
return 1;
}), 2, __x);
}
export {
fn ,
a ,
}
/* No side effect */
In the generated code, __x
is clearly undefined, which leads to a ReferenceError
at runtime. I found that replacing _
with ...
in the ReScript code fixes the error. Apart from this issue, our migration to the new version is progressing without any major problems.
You can see the original code and its behavior on the ReScript playground here: ReScript Playground.
Sorry I haven’t had a chance to post about this since it was discovered (in July! ) but my rescript-nodejs
library isn’t really usable in uncurried mode since it leverages @obj
with optional parameters. If I don’t migrate off it, uncurried mode will require all optional fields to be set which is a bit pointless. I’ve been slowly working on a branch to fix this using records.
Unfortunately it uses a sneaky trick with @obj
definitions that isn’t covered by records with optional fields. Because @obj
definitions are external
, it opens up the opportunity to use @as
to set a parameter value (and thus object property) without revealing it to the call site.
This is critical for the NodeJS Stream API, where the objectMode
property completely changes the type of the stream.
The code is here, which binds to both regular and object streams, but I’ve extracted a short example to the playground:
As far as I can tell there’s no way to do this without either @obj
or a wrapper function.