Hacker News new | ask | show | jobs
by raphinou 2201 days ago
Can you share information about your experience? I'm currently working on a F# project, enjoying the functional approach, while having a lot of libraries available on the .Net platform. The |> operator is one I use all over the code, but Rust doesn't support custom operators. Is that annoying, or not at all? Is your code less functional and more imperative style due to Rust?
2 comments

The |> operator I miss, but rust have a near similar feel with iterators:

    let a= [1, 2];
    a.iter().filter(|x|..).map(|x|...)
I think I'm more functional in a lot of areas where in F# can't (or don't know how). One reason?:

https://doc.rust-lang.org/std/convert/trait.Into.html

This is THE feature I wish other langs copy. Combined with serde:

https://github.com/serde-rs/serde

Is possible to cut a lot of boilerplate related to data transformation (that is the main task in my case).

> Is your code less functional and more imperative style due to Rust?

I would imagine so. Rust doesn't support tail call optimization, and variables are immutable only by default.

LLVM should optimize tailcalls and sibcalls. But tail call optimization has unexpected interactions with the extended RAII that Rust uses because stuff has to be dropped at the end of its lifetime, so the code that's running in "tail" position is sometimes not what you expect.
As a beginner to Rust I'm surprised by this. Given the Rust compiler is able to figure out the lifetimes in the recursive case, you'd think the lifetimes within the tail-optimized loop would be same. Doesn't the lexical scoping of the loop's body have the equivalent lifecycle of a recursive call (drop at the end of the loop vs the end of the function)?