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

Use a custom type to represent dropped input #72

Closed
robrix opened this issue Feb 22, 2015 · 1 comment · Fixed by #74
Closed

Use a custom type to represent dropped input #72

robrix opened this issue Feb 22, 2015 · 1 comment · Fixed by #74
Milestone

Comments

@robrix
Copy link
Owner

robrix commented Feb 22, 2015

Swift 1.2b1 prefers an overload taking … -> () to one taking … -> T, and thus type inferencing will produce the incorrect type when using closure literals. While this is clearly a bug, there’s no telling whether it’ll be fixed in Swift 1.2, or at all.

This affects reductions with --> in Madness, because where Swift 1.1 would have inferred this:

let alternation = %"x" | (%"y" --> { _ in 1 })

to have type Parser<String, Either<String, Int>>.Function, in Swift 1.2 it has type Parser<String, String?>.Function (due to the overload of | which drops ignored parses on its right-hand side).

If we replace () with some Ignored type in the relevant API, then we’re insulated from any changes to the semantics of () in future releases of Swift.

Any extant reductions by closures taking advantage of the existing overloads to cause input to be dropped will be broken; however, this is bad behaviour anyway, and too easy to trigger by accident due to Swift’s preference for statements over expressions.

@robrix
Copy link
Owner Author

robrix commented Feb 22, 2015

I also like that the type says what it does and does what it says. Ignore is much clearer than () or Void for this purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant