-
Notifications
You must be signed in to change notification settings - Fork 71
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
Add fromFoldable #55
Add fromFoldable #55
Conversation
If it doesn't cause a circular dependency adding a tailrec dependency sounds good to me 👍 |
Sounds good. |
This one is stack-safe. Unfortunately I couldn't work out how to do it with |
781c515
to
7e54477
Compare
This now fails because of this code: exports.sortImpl = function (f) {
return function (l) {
/* jshint maxparams: 2 */
return l.slice().sort(function (x, y) {
return f(x)(y);
});
};
}; Removing the |
👍 LGTM. |
Neat trick 👍 I feel slightly uneasy about passing the effectful instance foldableReplicated :: Foldable Replicated where
foldr f z (Replicated n x) = applyN n (f x) z
foldl f z (Replicated n x) = let stupid = f z x
in applyN n (flip f x) z
foldMap = foldMapDefaultR Apart from that, it looks good to me, too! I'm eagerly awaiting |
@sharkdp That's a good point. I was a bit uneasy about this too, but wasn't able to come up with an example that broke things. Maybe a better implementation would be something (conceptually) similar to |
This new implementation has what I would deem acceptable performance, ~100ms to run |
Looks good 👍. Concerning the benchmark, a comparison to the |
(I was expecting the stateful one to be quite a lot faster.) |
Cool, thanks! I also expected a bigger difference.. |
Unfortunately my tool is not very good at labeling the axes... but it looks like it is quite a lot faster for smaller arrays (<100,000 elements), at least. Anyway I'm fairly certain the |
12aa86c
to
6866012
Compare
I've just squashed the commits, so the stateful implementation is gone now, but for anyone looking at this in the future, it was: foreign import fromFoldableImpl :: forall f a.
(forall b. (b -> a -> b) -> b -> f a -> b) -> f a -> Array a
fromFoldable :: forall f a. (Foldable f) => f a -> Array a
fromFoldable = fromFoldableImpl foldl exports.fromFoldableImpl = function (foldl) {
return function (xs) {
var result = [];
var push = function (x) { result.push(x); };
var push_ = function () { return push; };
foldl(push_)(null)(xs);
return result;
};
}; |
Last I knew using |
I agree with @garyb |
@hdgarrood could you rebase on the latest master please? |
5c98481
to
22369a5
Compare
Done. |
This should speed it up. I might do a proper benchmark (once the core libraries are all updated).
Thanks! |
Refs #53. This implementation seems to work, but is not stack-safe (on my machine, on node.js, it fails with >= 5658 elements). Could
arrays
add atailrec
dependency, maybe?