Confusing error when using do instead of for

ace2620
Opened by Brian Anderson at 2012-12-09 07:04:43

Range should have been called with for

./uuid.rs:90:41: 99:9 error: mismatched types: expected `bool` but found `()` (bool vs ())
./uuid.rs:90         do uint::range(0u, 100000u) |_i| {
./uuid.rs:91             let uuid = uuid();
./uuid.rs:92             assert uuid == from_str(to_str(uuid));
./uuid.rs:93
./uuid.rs:94             let uuid = uuid_random();
./uuid.rs:95             assert uuid == from_str(to_str(uuid));
  1. If we'd remove the do-expression and rename for to do, what would we lose?

    kud1ing at 2012-07-06 07:13:35

  2. @Lenny222 for only handles functions where the operator is a stack closure returning bool. Things like map and spawn won't work with it.

    We could possibly have one keyword that just does the right thing based on the closure type. do x.each { doesn't sound so bad. for spawn { isn't great.

    Brian Anderson at 2012-07-06 07:38:19

  3. Having only a do "do"-ing the right thing sounds like a win.

    kud1ing at 2012-07-06 07:44:05

  4. Seems like the typechecker should attempt to see if "for" would have been the right thing, and said "Did you mean 'for'?". (Same for the other way around.)

    ben blum at 2012-07-08 04:23:16

  5. @Lenny222 I feel like that would be too magical. Silently inserting the equivalent of return true at the end of a lambda, without a special form to indicate this is happening, doesn't sit right with me.

    Patrick Walton at 2012-09-06 15:50:18