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

const overload accepting a closure for memoized lazy evaluation #32

Open
robrix opened this issue Feb 25, 2015 · 4 comments
Open

const overload accepting a closure for memoized lazy evaluation #32

robrix opened this issue Feb 25, 2015 · 4 comments

Comments

@robrix
Copy link
Owner

robrix commented Feb 25, 2015

I think const might be more useful if it were marked as @autoclosure(escaping). As it is, you can’t use it for any kind of effectful case analysis because effects occur regardless of the branch taken, which defeats the purpose of using case analysis for effects.

@robrix
Copy link
Owner Author

robrix commented Feb 25, 2015

This would be very much in the spirit of Haskell, since Haskell is lazily-evaluated by default.

@jspahrsummers
Copy link

The semantics of @autoclosure(escaping) are non-obvious to most folks, and it doesn't help that you'd have to read the documentation to realize that it automatically closes over your value.

I think escaping autoclosures are an anti-feature, and their use should be discouraged. If you want to support lazy evaluation, accept an explicit closure.

@robrix
Copy link
Owner Author

robrix commented Feb 28, 2015

That’d look like so:

fooBarQuux.analysis(
    ifFoo: const(0),
    ifBar: const { ++x },
    ifQuux: { $0 + $1 })

Yeah, I agree—that’s much less problematic.

@robrix robrix changed the title Should const be @autoclosure(escaping)? const overload accepting a closure for lazy evaluation Feb 28, 2015
@robrix
Copy link
Owner Author

robrix commented Feb 28, 2015

It’s hardly a constant unless it memoizes as well. I think that lines up nicely with this.

@robrix robrix changed the title const overload accepting a closure for lazy evaluation const overload accepting a closure for memoized lazy evaluation Feb 28, 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

No branches or pull requests

2 participants