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

make fix polymorphic in two type variables #30

Merged
merged 4 commits into from
Sep 6, 2015

Conversation

DanielAsher
Copy link
Contributor

and add an exception enabled version fixt

return { x in f(fix(f))(x) }
}

/// The fixpoint (or Y) combinator computes the least fixed point of an equation. That is, the first
/// point at which further application of x to a function is the same x.
/// fixt is the exception enabled version of fix.
Copy link
Member

Choose a reason for hiding this comment

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

Can you add an extra line of

///

above this line?

Copy link
Member

Choose a reason for hiding this comment

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

And put fixt in a pair of backticks?

comment line /// added above `fixt` definition.
/// The fixpoint (or Y) combinator computes the least fixed point of an equation. That is, the first
/// point at which further application of x to a function is the same x.
/// fixt is the exception-enabled version of fix.
///
Copy link
Member

Choose a reason for hiding this comment

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

Whoops, other way around:

/// The fixpoint (or Y) combinator computes the least fixed point of an equation. That is, the first
/// point at which further application of x to a function is the same x.
///
/// `fixt` is the exception-enabled version of fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good to know markdown is partially supported :)

On Sun, Sep 6, 2015 at 9:18 PM Robert Widmann notifications@github.com
wrote:

In Swiftx/Combinators.swift
#30 (comment):

return { x in f(fix(f))(x) }

}

+/// The fixpoint (or Y) combinator computes the least fixed point of an equation. That is, the first
+/// point at which further application of x to a function is the same x.
+/// fixt is the exception-enabled version of fix.
+///

Whoops, other way around:

/// The fixpoint (or Y) combinator computes the least fixed point of an equation. That is, the first

/// point at which further application of x to a function is the same x.

////// fixt is the exception-enabled version of fix.


Reply to this email directly or view it on GitHub
https://github.com/typelift/Swiftx/pull/30/files#r38825650.

@pthariensflame
Copy link
Member

Why are we not using rethrows here?

@CodaFi
Copy link
Member

CodaFi commented Sep 6, 2015

(For my own memory, tying this to #29).

@DanielAsher
Copy link
Contributor Author

@pthariensflame : The swift-2.0 compiler complains with:
Error: Only function declarations may be marked 'rethrows'.

@DanielAsher
Copy link
Contributor Author

did I break the Travis CI build?

@CodaFi
Copy link
Member

CodaFi commented Sep 6, 2015

The build is broken anyways because Travis is using 1.2 while swift-develop is on 2.0. It's safe to ignore.

@CodaFi
Copy link
Member

CodaFi commented Sep 6, 2015

Your error is because the function is missing a throws in argument position.

@CodaFi
Copy link
Member

CodaFi commented Sep 6, 2015

This definition compiles

public func fixt<A, B>(f : (A throws -> B) throws -> (A throws -> B)) rethrows -> A throws -> B {
    return { x in try f(fixt(f))(x) }
}

@DanielAsher
Copy link
Contributor Author

Thanks for this. Looks better to me.
I'll check this on my client code and submit if successful.

On Sun, Sep 6, 2015 at 9:30 PM Robert Widmann notifications@github.com
wrote:

This definition compiles

public func fixt<A, B>(f : (A throws -> B) throws -> (A throws -> B)) rethrows -> A throws -> B {
return { x in try f(fixt(f))(x) }
}


Reply to this email directly or view it on GitHub
#30 (comment).

fixt now uses rethrows correctly
@DanielAsher
Copy link
Contributor Author

@pthariensflame @CodaFi thanks for the fix of fixt 👍

I'd love to have a clear idea about the difference in behaviour of the rethrows version of fixt.

Please do add any comments here that will help clarify this difference.

@CodaFi
Copy link
Member

CodaFi commented Sep 6, 2015

From the type signature you presented, it says the fixpoint of a throwing function always throws itself. While we're making that call, we may as well assume the body after the recur can throw too, in which case we shouldnt eat the error.

@CodaFi
Copy link
Member

CodaFi commented Sep 6, 2015

@DanielAsher It was an honor and a pleasure to be the outlet for your first github pull request. Thank you so much for the changes you've made here ✨

CodaFi added a commit that referenced this pull request Sep 6, 2015
make `fix` polymorphic in two type variables
@CodaFi CodaFi merged commit a2329bc into typelift:swift-development Sep 6, 2015
@DanielAsher DanielAsher deleted the swift-development branch September 9, 2015 10:42
DanielAsher pushed a commit to DanielAsher/Swiftx that referenced this pull request Sep 9, 2015
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.

3 participants