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

Applicative functor interface #6

Open
asajeffrey opened this issue Feb 14, 2016 · 0 comments
Open

Applicative functor interface #6

asajeffrey opened this issue Feb 14, 2016 · 0 comments
Assignees

Comments

@asajeffrey
Copy link
Owner

Really, the interface should be an applicative functor. The idea would be:

interface Parser { ... fn apply<P>(self, p: P) -> Apply<Self, P> { ... } ... }
impl<P,Q,Str> Uncommitted<Str> for Apply<P,Q> 
    where P: Uncommitted<Str>,
          Q: Committed<Str>,
          P::Output: Function<Q::Output>, 
{ ... }

so you could write something like:

character(...).emitting(myfun).apply(this).apply(that);

This would support Kleene Star as well, with something like:

interface Parser { ... fn apply_star<P>(self, p: P) -> ApplyStar<Self, P> { ... } ... }
impl<P,Q,Str> Uncommitted<Str> for ApplyStar<P,Q> 
    where P: Uncommitted<Str>,
          Q: Uncommitted<Str>,
          P::Output: Function<Q::Output, Output = P::Output>, 
{ ... }

For example, the current p.star(f) would be:

emit(f).apply_star(p)

and the current p.plus(f) would be:

p.map(|x| f().apply(x)).apply_star(p)

this uses F: FnOnce(X) -> F as a replacement for Consumer<F>.

@asajeffrey asajeffrey self-assigned this Feb 14, 2016
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

No branches or pull requests

1 participant