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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Swiftx/Combinators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,17 @@ public func |> <A, B>(a : A, f : A -> B) -> B {
/// point at which further application of x to a function is the same x.
///
/// x = f(x)
public func fix<A>(f : ((A -> A) -> A -> A)) -> A -> A {
public func fix<A, B>(f : (A -> B) -> A -> B) -> A -> B {
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.
///
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.

/// `fixt` is the exception-enabled version of fix.
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) }
}
/// On | Applies the function on its right to both its arguments, then applies the function on its
/// left to the result of both prior applications.
///
Expand Down