F# Units of measure - 'lifting' values to float

前端 未结 2 1181
别跟我提以往
别跟我提以往 2020-12-11 09:17

When importing numbers from a csv file, I need to convert them to floats with unit.

Currently I do this with an inline function:

data |> List.map          


        
相关标签:
2条回答
  • 2020-12-11 09:44

    Is there any reason why you have to map twice? What's wrong with this:

    data |> List.map (fun x -> (float x) * 1.0<m>)
    
    0 讨论(0)
  • 2020-12-11 09:50

    It looks like units of measure can't be type parameters for the moment (no idea if this will change). So the shortest way to write this is:

    data |> List.map float |> List.map ((*) 1.0<m>)
    

    EDIT

    See also now FloatWithMeasure here

    http://msdn.microsoft.com/en-us/library/ee806527(VS.100).aspx

    0 讨论(0)
提交回复
热议问题