-
Notifications
You must be signed in to change notification settings - Fork 19
free-ish representation of Eff in JS #29
Comments
I think it would be good if you could demonstrate this approach in a repo, although I don't think it's a good default for |
Here it is, it's stacksafe, and should be fast, (haven't done benchmarks, yet) I could have made port of ps-catlist to js, but uncons might still have O(n) performance (if i understand it correctly), which would not be useful, tho having cat list with 0(1) uncons would be pretty useful (will take a look at okasaki) and will avoid need to go down to the leaf nodes in unsafeRun. |
Looks interesting, but I'll need to study it more. Perhaps you could make a repo and package it up as a PureScript library on top of |
Currently this is what results look like:
This is how test structures are generated: applyLoop :: Monad m => (Int -> m Unit) -> Int -> m Unit
applyLoop eff max = go (pure unit) 0
where
go acc n | n == max = acc
go acc n = go (acc <* eff n) (n + 1)
bindRightLoop :: Monad m => (Int -> m Unit) -> Int -> m Unit
bindRightLoop eff max = go (pure unit) 0
where
go acc n | n == max = acc
go acc n = go (eff (max - n - 1) >>= const acc) (n + 1)
bindLeftLoop :: Monad m => (Int -> m Unit) -> Int -> m Unit
bindLeftLoop eff max = go (pure unit) 0
where
go acc n | n == max = acc
go acc n = go (acc >>= const (eff n)) (n + 1)
mapLoop :: Monad m => Int -> m Int -> m Int
mapLoop max i =
if max == 0
then i
else mapLoop (max - 1) (map (_ + 1) i) Note that generations must be tail call optimized so stack is not overflowed during generation. Max numbers for particular test type is restricted because of
So now there is heap memory and time constraints only. Right associated binds perform extremely well, my guess is that operations array is smaller in that case. I used bind based implementations of map and apply but they performed badly than normal implementation. Need to do a bit more testing & benchmarking. but here is the code safareli/purescript-ef#1 |
I think it looks great! It would be interesting to compare it to |
This is really cool, but just an FYI wrt minibench. You have to be sure to initiate a manual GC between each test. GC from previous runs will most definitely affect subsequent runs. I hit this problem when benching |
have you done similar thing somewhere, can you link that? |
For v8 you just call |
And call node with |
GC already gets run once inside |
@paf31 Maybe I was using an old version? |
Thanks! I created an initial PR if you wanna review |
If representation of Eff in JS runtime, was free monad-ish way, like this:
then:
This will make bind stack safe by default (no need for MonadRec)
Disadvantages:
Control/Monad/Eff.js
first to get reference tounsafeRun
and then use it to run the Eff.Advantages:
The text was updated successfully, but these errors were encountered: