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
.
let t : TimedValue<double> = { ts = DateTime.Today; value=5.0}
A leading apostrophe is used to declare a type argument. So, you've declared a generic value but, by specifying value=5
you've constrained the type arg to be int
. You could also use a wildcard in place of the type arg:
let t : TimedValue<_> = { ts = DateTime.Today; value=5.0}
or remove the type annotation completely:
let t = { ts = DateTime.Today; value=5.0}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With