I know this will be an unpopular opinion, but pure functions would be a massive win for Rust, especially if the eventual goal is high performance, highly parallelizable (browser rendering engines..) development.
The typestate system did seme very complex but isn't there a middle ground via annotations perhaps? A subset of primitives and core functions can be annotated as pure and then any function calling only pure functions can itself be annotated as pure. There will be legal, pure functions that cannot be expressed this way, but using annotations and percolating effect tracking (similar to mutable fields in structs) seems like it shouldn't be too complex. Coming from the Haskell world, not having pure functions would be a considerable deficit in the language that is so close to being a best of both worlds descendant of C and Haskell. On Tue, Apr 30, 2013 at 9:57 AM, Tim Chevalier <[email protected]>wrote: > On Mon, Apr 29, 2013 at 9:30 PM, Erik S <[email protected]> wrote: > > On 4/29/2013 2:00 PM, Graydon Hoare wrote: > >> Yes. Formalizing and completing the definition of the constant > >> expression subgrammar would be extremely valuable. It's one of the > >> major high-risk areas remaining the the design space. -Graydon > > VHDL is a very different language from Rust (it's a hardware design > > language, not a normal programming language), but it has the nicest > > constant system I've worked with. > > > > The rule is basically that constant expressions can contain: > > > > Literals (i.e. 5, 0x20) > > Expressions that depend on constants (i.e. 0x5 + 10 * const_k) > > Any "pure" function whose arguments are constant. (i.e. 5 + f_pure(5, > > const_k) ) > > > > It's this last rule that is truly beautiful. You can use the same > > functions in both constant initialization and run-time code, with only > > the requirement that they are pure. Pure functions are ones whose output > > depends only on their arguments (and constants). Allowing functions to > > initialize constants avoids the whole annoyance in C/C++ where you have > > to use macros to make things compile-time const. It also allows a > > surprising amount of compile-time optimization. > > > > I don't know how realistic this is for constants in a language like rust > > - but it would be very elegant if it could work. > > > > We used to have a notion of pure functions in Rust, but that was > removed recently. It originally existed for typestate (a feature we > removed a while ago) and more recently to assist the borrow checker. > We removed it because in Rust, it was impractical to define an > easily-checkable pure subset of the language. Bringing it back in is > somewhat less likely than adding significant whitespace. > > Cheers, > Tim > > > > -- > Tim Chevalier * http://catamorphism.org/ * Often in error, never in doubt > "Too much to carry, too much to let go > Time goes fast, learning goes slow." -- Bruce Cockburn > _______________________________________________ > Rust-dev mailing list > [email protected] > https://mail.mozilla.org/listinfo/rust-dev >
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
