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

There should be a way to mark blocks as pure. #2758

Closed
paulstansifer opened this issue Jun 29, 2012 · 2 comments
Closed

There should be a way to mark blocks as pure. #2758

paulstansifer opened this issue Jun 29, 2012 · 2 comments
Labels
A-typesystem Area: The type system C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@paulstansifer
Copy link
Contributor

The following code has to name two functions.

pure fn hash(x: @str) -> uint { str::hash(*x) }
pure fn eq(x: @str, y: @str) -> uint { str::eq(*x,*y) }
ret hashmap(hash, eq);

It'd be nice if we could write:

ret hashmap(pure {|x: @str|str::hash(*x)}, pure {|x,y|str::eq(*x,*y)});

...or even (with type inference, if possible):

ret hashmap({|x: @str|str::hash(*x)}, {|x,y|str::eq(*x,*y)});
@jld
Copy link
Contributor

jld commented Jul 14, 2012

It sounds as if you want those functions to be pure, not the expressions that compute the function values. I have the same problem in something I'm writing: exposing access to a piece of unique data within a data structure via a callback, which has to be pure to be able to safely borrow the argument. And the only way to create a value to inhabit a pure fn type is with a named fn statement, which doesn't close over its environment, which leaves me back in C-land passing around explicit environment structs (and not being able to use do-notation). So that's kind of annoying.

I tried modifying the parser to accept pure fn expressions, but that ran into the assert at typeck/check.rs line 197, and at this point I do not even pretend to understand what's going on here.

@graydon
Copy link
Contributor

graydon commented Mar 13, 2013

purity is going away, closing this as WONTFIX

@graydon graydon closed this as completed Mar 13, 2013
oli-obk pushed a commit to oli-obk/rust that referenced this issue Jan 30, 2023
RalfJung pushed a commit to RalfJung/rust that referenced this issue Feb 26, 2023
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

3 participants