-
Notifications
You must be signed in to change notification settings - Fork 301
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
curriing limit to 10 is low #3514
Comments
When running fable in non watch mode ( However, if running it in watch mode ( Fable If you revert to Fable |
@ncave I am looking into fixing this issue because having infinite currying/uncurrying is really important for libraries like Thoth.Json and Fable.Form. I found the previous implementation of the fable-library/Util.ts const CURRIED = Symbol("curried");
function _curry(args: any[], arity: number, f: Function): (x: any) => any {
return (arg: any) => arity === 1
? f(...args.concat([arg]))
// Note it's important to generate a new args array every time
// because a partially applied function can be run multiple times
: _curry(args.concat([arg]), arity - 1, f);
}
export function curry(arity: number, f: Function): Function | undefined {
if (f == null || f.length === 1) {
return f;
}
else if (CURRIED in f) {
return (f as any)[CURRIED];
} else {
return _curry([], arity, f);
}
} But when I try to apply it in place of this code Fable/src/Fable.Transforms/Replacements.Util.fs Lines 379 to 389 in 7b51c59
When trying different approach I also had issues with mangling signature changing, etc. Probably because the code changed too much between Fable 4 and Fable 3, so I can naïvely patch it... While reading through the code I found out that the new curry/uncurry implementation is using some kind of global storage. Fable/src/fable-library/Util.ts Line 656 in 7b51c59
Can't this global storage be out of sync depending on the code order? I mean it seams like it store the last function called with I suppose that storage is to work around "partial application and side effets" as if I replace it with an older implementation like: export function curry2<T1, T2, TResult>(f: (a1: T1, a2: T2) => TResult) {
return ((a1: T1) => (a2: T2) => f(a1, a2));
} then 2 tests are failings. Do you have any guidance to give me ? |
@MangelMaxime If you need more than 10 levels, perhaps just add extra curry/uncurry to Here is when the first 10 curry/uncurry were introduced. Here is a description of why those tests are failing. To (mis)quote B.G., |
I've heard that typescript have variadic tuples. Maybe it helps. https://instil.co/blog/crazy-powerful-typescript-tuple-types/ |
@ncave Thank for the commit, this is what I was working with. However, I feel like others things moved in the code too and I can't easily revert this commit. Will give it another try.
This will increase the bundle size and is a temporary solution, nothing prevent users to have forms with more that 10 flats fields (bad UX probably but I see a lot of them), or JSON with more that 10 properties (in this case I will probably resort to this fix for now, if I can't make it work with infinite currying. @ncave Do you know why we need to store uncurried function inside of a |
Yes, it's described in #3378:
|
I will need to re-read the code because I don't understand how that WeakMap stuff works. I don't understand how it know which functions to retrieve. To me it looks like if Meaning that when Unless, curry2 and uncurry2 are always right after one another which I don't think is possible to guarantee with |
If I'm not mistaken, the WeakMap is just a storage, the key is stored in each function object as property. |
Ohhh, I think you are right. A new function is created each time, and that function is what is used as a key. So each time, there is a new instance so it doesn't override the previous |
@MangelMaxime Right, we haven't implemented that for Rust yet, so in Rust partial application with side effects can run the side effects twice (or more). |
Description
I've tried to create a form with 11 fields with Fable.Form .
When compiling to JavaScript Fable generates the wrong function call & export
Fable 4.0.1 generate the working code.
Repro code
https://github.com/slyshykO/big-form
Expected and actual results
Fable compile working code.
Related information
The text was updated successfully, but these errors were encountered: