-
Notifications
You must be signed in to change notification settings - Fork 33
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
Added oneShot to Codensity continuation #79
base: master
Are you sure you want to change the base?
Conversation
Is it worth adding a Codensity f <*> Codensity g =
Codensity $ oneShot (\bfr -> f $ oneShot (\ab -> g $ oneShot (\x -> bfr (ab x)))) Or the one from IOSim which only uses it for the first continuation. (<*>) = \df dx -> IOSim $ oneShot $ \k ->unIOSim df (\f -> unIOSim dx (\x -> k (f x))) |
3b0d631
to
4af81da
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for getting this started, @Icelandjack.
I find it difficult to review this at the moment, as this PR appears to have introduced some unrelated changes, which I don't believe were intended.
An interesting question. Considering that GHC invented the |
0263e08
to
915caae
Compare
I've fixed it @RyanGlScott, as to your questions I asked Marcin Szamotulski about it and he did the following benchmark: input-output-hk/io-sim#149. One test drops from 6.7ns to 5.955ns but he says he's going to run a larger simulation to see if it makes a more significant difference. |
7c46c02
to
8fddcb5
Compare
Thanks, this is looking better. Two thoughts:
|
Marcin had mentioned that idea previously
I can write a blurb and link as well, but what is the best format of linking to a note from ghc? |
Wow, the fact that it regressed performance is indeed surprising. I suppose this means that we really should be benchmarking these
I think it would be helpful to write our own Note in the module which defines -- See Note [oneShot] for an explanantion of why we use oneShot below
instance Functor (Codensity (k :: j -> TYPE rep)) where
fmap f (Codensity m) = Codensity (\k -> m (\x -> k (f x)))
{-# INLINE fmap #-}
instance Apply (Codensity (f :: k -> TYPE rep)) where
(<.>) = (<*>)
{-# INLINE (<.>) #-}
-- ...
{-
Note [oneShot]
~~~~~~~~~~~~~~
The code in this module uses oneShot because ...
The inspiration for this trick comes from ... (cite the GHC Note here)
We deviate slightly from the presentation shown in that Note because
of performance reasons, which are explained in ...
-} |
Solving issue #78. Rewrote functions to add
oneShot
to the continuation: