- 
                Notifications
    You must be signed in to change notification settings 
- Fork 834
Closed
Labels
Area-Compiler-OptimizationThe F# optimizer, release code gen etc.The F# optimizer, release code gen etc.Feature Request
Milestone
Description
Consider the following snippet:
open System
let f() =
  for x in 0 .. 15 do
    Console.WriteLine xIt produces a nice, C#esque for-loop. Now consider this one:
open System
let g() =
  for x in 0 .. 2 .. 15 do
    Console.WriteLine xIt creates a sequence and then enumerates it. And it also has a consecutive pair of ldnull; pop; twice, as well as a needless unit local.
Producing a for (int i = 0; i < 15; i += 2) in the second case would have been much more efficient. We could even generalize it to arbitrary types with an addition operator, not just ints. Furthermore, in the first example, replacing the loop with for x in 0.0 .. 15.0 creates a sequence too.
In addition, using like for x in [0 .. 15] does correctly produce a list, but the compiler should warn to better remove the brackets when using a ranged list literal in a loop.
heronbpv and abelbraaksma
Metadata
Metadata
Assignees
Labels
Area-Compiler-OptimizationThe F# optimizer, release code gen etc.The F# optimizer, release code gen etc.Feature Request
Type
Projects
Status
Done