如何构建float <meter>列表?

Mar*_*tin 3 f#

通常,当我需要构建一个从0到10的列表时,我只是这样做:[0..10].这给了我一个从0到10的整数列表.但这次我需要一个从0到10的浮点列表.有没有办法做到这一点?

let testFunc (x: float<metre>) = 
    x

let otherTestFunc =
    [0.0 .. 10.0] // How do I make this return float<metre>
    |> List.map (fun x -> testFunc x)
Run Code Online (Sandbox Code Playgroud)

Joh*_*mer 5

我不久前向F#团队报告过这个问题,但是在使用Measures时需要手动指定步骤.

let testFunc (x: float<metre>) = 
    x

let otherTestFunc =
    [0.0 <metre> .. 1.0<metre> .. 10.0 <metre>] // How do I make this return float<metre>
    |> List.map (fun x -> testFunc x)
Run Code Online (Sandbox Code Playgroud)

  • 作为旁注,这里似乎可以使用推理来避免冗余:`[0.0 <_> .. 1.0 <_> .. 10.0 <_>]`typechecks as`metre`是通过使用`testFunc推断的`. (3认同)