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

Optimizable Freer #8

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open

Optimizable Freer #8

wants to merge 39 commits into from

Conversation

robrix
Copy link
Owner

@robrix robrix commented Jul 20, 2017

This PR defines Map and Seq constructors for Freer in an attempt to enable optimization by analyzing subsequent values.

A few of the mechanisms operating over Seq are defined by rewriting the Seq as a Then; this includes the Traversable instance (because this would require splitting the Seq up into separate values, necessarily parameterized by different types), and also project & therefore iterFreer. Unfortunately, this means that sequenceA . sequenceA /= id (which in fairness is generally the case, e.g. for Maybe), project . embed /= id, &c.

go (Map f a) = algebra a Nothing f
go (Seq f a b) = algebra a (Just b) (go . flip fmap b . f)
go (Then a f) = algebra a Nothing (go . f)
{-# INLINE iterLookahead #-}
Copy link
Owner Author

Choose a reason for hiding this comment

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

I’m not sure just yet whether this will cut it, but iterLookahead provides the algebra with the next step, when it’s available. In theory, this should accommodate algorithms requiring lookahead.

@robrix
Copy link
Owner Author

robrix commented Jul 21, 2017

cc @tclem

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