typelift / Swiftx

Functional data types and functions for any project
BSD 3-Clause "New" or "Revised" License
219 stars 28 forks source link

make `fix` polymorphic in two type variables #30

Closed DanielAsher closed 9 years ago

DanielAsher commented 9 years ago

and add an exception enabled version fixt

pthariensflame commented 9 years ago

Why are we not using rethrows here?

CodaFi commented 9 years ago

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

DanielAsher commented 9 years ago

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

DanielAsher commented 9 years ago

did I break the Travis CI build?

CodaFi commented 9 years ago

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

CodaFi commented 9 years ago

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

CodaFi commented 9 years ago

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 commented 9 years ago

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 https://github.com/typelift/Swiftx/pull/30#issuecomment-138123756.

DanielAsher commented 9 years ago

@pthariensflame @CodaFi thanks for the fix of fixt :+1:

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 commented 9 years ago

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 commented 9 years ago

@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 :sparkles:

:boat: