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

Consider giving the Y-combinator, fix, two type parameters. #29

Closed
DanielAsher opened this issue Sep 6, 2015 · 6 comments
Closed

Consider giving the Y-combinator, fix, two type parameters. #29

DanielAsher opened this issue Sep 6, 2015 · 6 comments

Comments

@DanielAsher
Copy link
Contributor

Currently fix is defined so:

public func fix<A>(f : ((A -> A) -> A -> A)) -> A -> A {
    return { x in f(fix(f))(x) }
}

I have found the following fix more useful:

public func fix<T, U>(f: (T -> U) -> T -> U) -> T -> U {
    return { x in f(fix(f))(x) }
}

Could this act as a replacement, or addition, to the current fix?

cheers,

Daniel

@CodaFi
Copy link
Member

CodaFi commented Sep 6, 2015

Hm, it's an interesting proposal. What use cases have you run into where that version is more useful?

N.B. I kept fix polymorphic in only 1 type variable because fix usually looks like (A -> A) -> A, from η expansion our fix follows.

@pthariensflame
Copy link
Member

I'm in favor of this proposal. It's strictly more general without changing any of the existing uses.

@DanielAsher
Copy link
Contributor Author

Hi CodaFi,

thanks for the quick response. I'm trying out parser combinators, and loving it.

I was using robrix's Prelude, but Swiftz is swift-2.0 compatible, and looks to be a leader in this space.

Bit of a newbie, but you can see an example of my use case here

I'd be happy to create a PR if desired.

Will a fix that supports throws be a useful addition? I think I'll have an answer for you shortly...

@CodaFi
Copy link
Member

CodaFi commented Sep 6, 2015

@DanielAsher Would you be up for submitting a pull request, or shall I do it?

@DanielAsher
Copy link
Contributor Author

@CodaFi I be rather excited to submit a PR - it would be my first!

I'd like to check out fix's behaviour with throws before I do though...

@DanielAsher
Copy link
Contributor Author

@CodaFi @pthariensflame thanks so much for quick and insightful responses 👍

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

3 participants