I feel that prototyping is hampered by not being able to quickly move some code to a function to save some repetition.
Once I type out the type signature for the function, it is actually longer to abstract something into a function than to just leave it in-line. Even if I do it twice, the type signature for doing something with 4-5 variables is going to be longer than the actual function body.
I tried to persevere and to actually do it in FizzBuzz:
https://bitbucket.org/iopq/fizzbuzz-in-rust/src/b5e7b36cdb2ac0e88e1802a0b3547f90184f7e09/src/lib.rs?at=master#cl-39
the result is super gross
fn accumulate<'a, T: Monoid>(tuples: &[(&'a str, &Fn(i32) -> bool)], i: i32) -> Option<T>
where &'a str: Into<T> {
tuples.iter().fold(None, |acc, &(concat_str, include_fn)|
append(acc, concat_str, include_fn(i))
)
}
these two lines take a monstrosity of a type signature for just two parameters
in fact my entire program written in line is just a few lines of code, most of the characters in my program are types
I understand that I should be clear in my pub fns because that’s my contract with the rest of the world, but I feel like my own private functions should give me type inference
this doesn’t just affect toy examples, the Go game AI player I’m working on:
I feel like I’m committing atrocious duplicated code in it because writing a function is actually longer and takes more time and effort and ends up being longer and possibly more difficult to read than just copy pasting two lines of code
This is a bad thing because duplicated code is harder to maintain. I would just write a macro, but macro definitions are also pretty gnarly-looking and they’re not hygienic in some regards.
Is there any other way for me to solve my issue that I’m overlooking?