Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a base
Env :env
monad toenvironment.lisp
. PreviouslyEnv :env
was just an alias forEnvT :env Identity
. Haskell definesReader
like this, and they can get away with it. GHC does a lot of work behind the scenes to fuse lambda calls, so wrapping the Identity monad is zero-cost at runtime for them. Coalton doesn't have that, so it's not.Here's a little microbenchmark that takes an Integer as the environment and a list of ints as an argument, and maps adding the environment Integer to all of the ints in the list inside the monad.( It does this very inefficiently, so it binds for every element in the list.)
Here are typical results on my machine, compiled in release mode:
The base
Env
runs ~3.26% faster than theEnvT
' which actually surprised me that it was so close. I'm not good enough at optimizing CL/Coalton to really know why that might be, other than speculating that the EnvT & Identity monads really don't do that much.The base
Env
did cons ~29% fewer bytes than theEnvT
version did, which is in line with what I would have expected. Also curious, the base version actually spent more time in GC, but I suspect that's just noise or a bad test setup on my part.