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'

Expected

... 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?

+3


source to share


2 answers


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

.

+5


source


Just guess, but what does the compiler say when you experiment with making your ints float?

from

let inds = [1;   2;  6;  8; 11; 12]
let vals = [10; 20; 30; 40; 50; 60]

      



in

let inds = [1.0;   2.0;  6.0;  8.0; 11.0; 12.0]
let vals = [10.0; 20.0; 30.0; 40.0; 50.0; 60.0]

      

+2


source







All Articles