Earlier quoted context omitted.
Note that Monoid here is ONLY for the reason that Cow doesn't satisfy Add. In fact, String doesn't satisfy it either. So I need to have a trait that allows me to call a function that concatenates my types. I already wrote how to concatenate Strings and Cow s in my Monoid crate so I'm just re-using that. It could be T: Concatenable for all I care, but the rest of the function needs to look this way, more or less. I on…
I'm not just talking about Monoid, I'm talking about the overall signature -- with the Fn and the abstractions it's very Haskelly. Such functions are not common in Rust. You find them (all the iterator adaptors, for one), and they can be "good Rust", but they're not common. Which is okay. (I don't disagree that Rust is more complicated than Python, just addressing GP's comment whether or not this is "good" rust.)
Introducing Rust Language Server
101–108 of 108 posts
Re: Introducing Rust Language Server
#102Earlier quoted context omitted.
There's plenty of fighting the compiler. error[E0281]: type mismatch: the type `fn(_) -> _ {tool::second:: }` implements the trait `std::ops::FnMut `, but the trait `for std::ops::FnMut ` is required (expected concrete lifetime, found bound lifetime parameter ) --> src\lib.rs:53:11 | 53 | .filter(apply(second, i)) | ^^^^^ | = note: required by `apply` error[E0271]: type mismatch resolving `for _ {tool::second:: } as…
I suspect I would - I'll happily guess if I can take a look at the code (or at least the signatures of "filter", "apply", "second" and "i").
filter is from the standard lib
apply is defined as
fn apply(mut f: F, a: A) -> impl FnMut(&B) -> C
where F: FnMut(&B) -> G,
G: FnMut(A) -> C,
A: Clone
{
move |b| f(b)(a.clone())
}
second comes fromhttps://github.com/Stebalien/tool-rs/blob/master/src/sequenc... which means you have to track down its implementation somewhere in macros
Re: Introducing Rust Language Server
#103Earlier quoted context omitted.
There's plenty of fighting the compiler. error[E0281]: type mismatch: the type `fn(_) -> _ {tool::second:: }` implements the trait `std::ops::FnMut `, but the trait `for std::ops::FnMut ` is required (expected concrete lifetime, found bound lifetime parameter ) --> src\lib.rs:53:11 | 53 | .filter(apply(second, i)) | ^^^^^ | = note: required by `apply` error[E0271]: type mismatch resolving `for _ {tool::second:: } as…
I suspect I would - I'll happily guess if I can take a look at the code (or at least the signatures of "filter", "apply", "second" and "i").
https://bitbucket.org/iopq/fizzbuzz-in-rust/src/920bd2bd1267...
this doesn't work, so I want you to tell me why
Re: Introducing Rust Language Server
#104Earlier quoted context omitted.
> I don't consider Rust to be a particularly complex language > I put it on par with Python Python doesn't have complicated lifetime errors, confusing trait not being satisfied errors. Python function declarations don't need three lines of code. I mean wtf is this? fn accumulate (tuples: &[(&'a str, &Fn(i32) -> bool)], i: i32) -> Option where T: From there's about ten language features in these lines of code that Pyt…
I consider "complexity" to refer to both the quantity of language features and the number of significant or surprising interactions that exist between every language feature. Rust and Python are both medium-complexity languages, but the difference is that in Python you can totally ignore e.g. generators or decorators or (oh god) metaclasses and still get work done. In Rust you really can't get work done until you und…
I would argue that Rust has a higher learning curve overall than any dynamic language because of its type system.
Re: Introducing Rust Language Server
#105Earlier quoted context omitted.
There's plenty of fighting the compiler. error[E0281]: type mismatch: the type `fn(_) -> _ {tool::second:: }` implements the trait `std::ops::FnMut `, but the trait `for std::ops::FnMut ` is required (expected concrete lifetime, found bound lifetime parameter ) --> src\lib.rs:53:11 | 53 | .filter(apply(second, i)) | ^^^^^ | = note: required by `apply` error[E0271]: type mismatch resolving `for _ {tool::second:: } as…
That's a bad error message. Please file a bug :) It sounds like you're returning closures, which is a very recent feature—it only became possible last month with the implementation of "impl Trait" IIRC. It takes time for features to mature.
Re: Introducing Rust Language Server
#106Earlier quoted context omitted.
I suspect I would - I'll happily guess if I can take a look at the code (or at least the signatures of "filter", "apply", "second" and "i").
I put the whole code in a separate branch for you: https://bitbucket.org/iopq/fizzbuzz-in-rust/src/920bd2bd1267... this doesn't work, so I want you to tell me why
Re: Introducing Rust Language Server
#107Earlier quoted context omitted.
I put the whole code in a separate branch for you: https://bitbucket.org/iopq/fizzbuzz-in-rust/src/920bd2bd1267... this doesn't work, so I want you to tell me why
Hmm fair enough, harder than I thought (I don't know Rust, the error just sounded sensible). It reads like the function you're passing into filter is supposed to be "lifetime-generic" taking a parameter whose lifetime comes from the for, but the function returned by apply has a fixed lifetime. But I can't see where it's getting the lifetime for that from, or what to do about it. I guess at that point I'd try adding a…
It would also work with a closure, but I wrote my code this way to avoid closures in the first place (I was going for point-free style).
I basically just have to write my own function:
https://bitbucket.org/iopq/fizzbuzz-in-rust/src/58bfa4c58c80...
this compiles, but it seems kind of pointless since I can only use this particular function in my case (because of the extra levels of references)
if I could use the tool.rs version, it would automatically generate all the implementations I need using macros
Re: Introducing Rust Language Server
#108Earlier quoted context omitted.
I put the whole code in a separate branch for you: https://bitbucket.org/iopq/fizzbuzz-in-rust/src/920bd2bd1267... this doesn't work, so I want you to tell me why
Hmm fair enough, harder than I thought (I don't know Rust, the error just sounded sensible). It reads like the function you're passing into filter is supposed to be "lifetime-generic" taking a parameter whose lifetime comes from the for, but the function returned by apply has a fixed lifetime. But I can't see where it's getting the lifetime for that from, or what to do about it. I guess at that point I'd try adding a…
I had to change the `apply` function to dereference as well, that way it doesn't run into the lifetime issue. It has something to do with higher ranked lifetimes (the inability to express the higher ranked lifetime)
This is the working version:
https://bitbucket.org/iopq/fizzbuzz-in-rust/src/95451868e27f...