F# Floating point ranges are experimental and may be deprecated

后端 未结 6 1782
猫巷女王i
猫巷女王i 2020-12-19 15:27

I\'m trying to make a little function to interpolate between two values with a given increment.

[ 1.0 .. 0.5 .. 20.0 ]

The compiler tells m

6条回答
  •  轮回少年
    2020-12-19 16:25

    You can also write a relatively simple function to generate the range:

    let rec frange(from:float, by:float, tof:float) =
       seq { if (from < tof) then 
                yield from
                yield! frange(from + by, tof) }
    

    Using this you can just write:

    frange(1.0, 0.5, 20.0)
    

提交回复
热议问题