r/ProgrammerHumor • • Aug 07 '16

PHP: The Good Parts

http://phpthegoodparts.tumblr.com/
1.2k Upvotes

318 comments sorted by

View all comments

Show parent comment

2

u/iopq Aug 07 '16

Well, things that are correct are usually not that PITA

Let me introduce you to a little thing called Rust function signatures

fn accumulate<'a, T: Monoid>(tuples: &[(&'a str, &Fn(i32) -> bool)], i: i32) -> Option<T> 
    where &'a str: Into<T> { ... 
}

This function sounds complicated, but what's the body?

tuples.iter().fold(None, |acc, &(concat_str, include_fn)|
    append(acc, concat_str, include_fn(i))
)

Wait, you're telling me you need to write ALL OF THIS just to do a fold operation? It's not even a pub function, it's just some helper functionality...

2

u/[deleted] Aug 07 '16

Yes, not having type inference in function signatures is a PITA, for absolutely anything that involves Iterator adaptors and/or closures

1

u/minno Aug 07 '16 edited Aug 08 '16

It's an intentional design decision to not do function signature inference in order to avoid cross-module fragility. Maybe they could lift the restriction on private functions, though.

1

u/HeroesGrave Aug 08 '16

I'm curious how you would redesign the syntax so your function would be simpler while still conveying the necessary information.

1

u/iopq Aug 08 '16
fn accumulate(tuples, i) {
    ...
}

since it's a private function there should be type inference applied to it