Hacker News new | ask | show | jobs
by jonshea 5269 days ago
If anyone is able, would you please explain to me these two questions from the quiz? I’m stumped.

Why does `toSeq` compile, but not `toIndexedSeq`?

    Set(1,2,3).toIndexedSeq sortBy (-_)
    Set(1,2,3).toSeq sortBy (-_)
Why does `h` compile, but `f` does not?

    def add(x: Int, y: Int) = x + y
    val f = add(1,_)
    val h = add(_,_)
1 comments

toIndexedSeq takes a type parameter (I'm not sure why - it appears unncessary) which means the result of toIndexedSeq is not known when it is attempting to infer the Ordering. toSeq doesn't take one, it's known to be Seq[Int].

The other looks like some quirk of partial application. It's unlikely there's any fundamental reason, only an implementation imperfection.

Good to know. Thanks Paul!