This code will generate the following warning
module TimeSeries
open System
type TimedValue<'T> = { ts : DateTime; value: 'T}
type TimeSerie<'T> = TimedValue<'T> seq
let t : TimedValue<'double> = { ts = DateTime.Today; value=5}
Warning:
This construct causes code to be less generic than indicated by the type annotations. The type variable ‘double has been constrained to be type ‘int’.
I am quite new to F#, I think the 5 is interpreted as an int and somehow F# tells me that I asked a double but it will be an int.
When I tried replacing 5 with 5. this told me that it was still constrained by the float type.
Should I somehow cast it in double or just remove the declaration part : TimedValue<'double> and let F# deal with the types ?
Remove the apostrophe before
double.A leading apostrophe is used to declare a type argument. So, you’ve declared a generic value but, by specifying
value=5you’ve constrained the type arg to beint. You could also use a wildcard in place of the type arg:or remove the type annotation completely: