Shortcut for creating an array with floating point in F #

F # has a shortcut for creating an array of numbers. For example, code

[1..10]

will create an array containing {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.

or

[-2..2]

will create {-2, -1, 0, 1, 2}.

Is there a related transcript for creating an array in F # in floating point increments? For example, an array such as {-2.0, -1.5, -1.0, -0.5, 0, 0.5, 1.0, 1.5, 2}, where the step is 0.5? Or uses a loop foror the whileonly way?

+4
source share
1 answer

Yes there is.

 [-2.0 .. 0.5 .. 2.0]

It creates

[-2.0; -1.5; -1.0; -0.5; 0.0; 0.5; 1.0; 1.5; 2.0]

Documentation: https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/loops-for-in-expression

+5
source

Source: https://habr.com/ru/post/1695521/


All Articles