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

Add fixed point combinator #372

Open
jbgi opened this issue Oct 14, 2018 · 1 comment
Open

Add fixed point combinator #372

jbgi opened this issue Oct 14, 2018 · 1 comment

Comments

@jbgi
Copy link
Member

jbgi commented Oct 14, 2018

useful for defining recursive functions via lambda syntax.

@jbgi
Copy link
Member Author

jbgi commented Oct 26, 2018

Here is what I have in mind:

  static <A> A fix(F<A, A> f, F<F0<A>, A> delay) {
    return new Object() {
      final A a = delay.f(() -> f.f(this.a));
    }.a;
  }
  static <A, B> F<A, B> rec(F<F<A, B>, F<A, B>> f, F<F0<B>, B> delay) {
    return new F<A, B>() {
      final F<A, B> rec = f.f(this);
      @Override
      public B f(A a) {
        return delay.f(() -> rec.f(a));
      }
    };
  }

Does that make sense?

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