I cannot understand this F # error message
The error messages generated by the F # compiler are sometimes confusing. For example:
open Deedle
let inds = [1; 2; 6; 8; 11; 12]
let vals = [10; 20; 30; 40; 50; 60]
let siv = Series(inds, vals)
let fbminmax b (s: Series<float, float>) =
if b then (Seq.min s.Values) else (Seq.max s.Values)
let sgi =
siv
|> Series.groupInto (fun i _ -> i % 2 = 0) fbminmax
printfn "%A" <| sgi
// error FS0001: Type mismatch. Expecting a
// 'bool -> Series<int,int> -> 'a'
// but given a
// 'bool -> Series<int,int> -> float'
// The type 'float' does not match the type 'int'
I understand there is a bug (the code works fine with the substitution Series<int,int>
Series<float,float>
in the definition fbminmax
). And I understand that
'bool -> Series<int,int> -> 'a'
... But I don't understand why the compiler says that it is given
'bool -> Series<int,int> -> float'
when it was asked fbminmax
which is
'bool -> Series<float,float> -> float'
Also, if the compiler is indeed given
'bool -> Series<int,int> -> float'
as he argued it should have been Ok with float
playing the part 'a
.
Can someone give some idea of ββwhat is going on?
source to share
The compiler error messages can indeed be somewhat cryptic. Solution: make it generic :-)
let fbminmax b (s: Series<'T, 'T>) =
if b then (Seq.min s.Values) else (Seq.max s.Values)
At the end of the day, the problem is that you are specifying fbminmax b (s: Series<float, float>)
but loading a string into it int
.
source to share