Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fsharp - Range evaluation [duplicate]

Tags:

syntax

f#

Is there a way one can get a range in descending order?

Ex

[1..4]

evaluates to

> val it : int list = [1; 2; 3; 4]

But

[4..1]

evaluates to

> val it : int list = []

Is there a different syntax to achive this without having to do a List.Reverse ?

like image 324
Srikanth Venugopalan Avatar asked Mar 13 '13 04:03

Srikanth Venugopalan


1 Answers

You have to do:

[4..-1..1]

The -1 is the step

like image 171
manojlds Avatar answered Sep 21 '22 04:09

manojlds