Skip to content
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

Church-encoded Writer carrier #369

Merged
merged 39 commits into from
Mar 15, 2020
Merged

Church-encoded Writer carrier #369

merged 39 commits into from
Mar 15, 2020

Conversation

robrix
Copy link
Contributor

@robrix robrix commented Mar 15, 2020

This PR introduces and benchmarks a high-performance Church-encoded Writer carrier. In benchmarks where it wraps IO, it outperforms every other carrier by quite a decent margin.

newtype StateC s m a = StateC { runStateC :: s -> m (s, a) }
newtype StateC s m a = StateC (s -> m (s, a))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops.

Comment on lines +66 to +68
Tell w' -> do
let !w'' = mappend w w'
pure (w'', ctx)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mappending strictly here made for a ~2.5x improvement to the performance of this carrier in the benchmarks.

Comment on lines +70 to +72
(w', a) <- runWriter (hdl (m <$ ctx))
let !w'' = mappend w w'
pure (w'', (,) w' <$> a)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I strongly prefer BangPatterns to seq for these; plus, it turns out that we were inadvertently making listen and censor too strict.

@robrix robrix merged commit a7f6519 into master Mar 15, 2020
@robrix robrix deleted the church-encoded-writer branch March 15, 2020 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant