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 an error (the code works fine with Series<int,int>
replacing Series<float,float>
in the definition of fbminmax
). And I understand that a
'bool -> Series<int,int> -> 'a'
was expected. But I do not understand why the compiler says that it was given a
'bool -> Series<int,int> -> float'
when it was given fbminmax
, which is a
'bool -> Series<float,float> -> float'
Moreover, if the compiler had indeed been given a
'bool -> Series<int,int> -> float'
as it claimed it did that should have been Ok with float
playing the role of 'a
.
Can someone provide some insight on what is going on?
答案 0 :(得分:4)
编译器错误消息确实有点神秘。解决方案:通用它: - )
let fbminmax b (s: Series<'T, 'T>) =
if b then (Seq.min s.Values) else (Seq.max s.Values)
最后的问题是您指定了fbminmax b (s: Series<float, float>)
,但是向其中提供了一系列int
。
答案 1 :(得分:2)
只是一个猜测,但是当你尝试使你的int浮动时,编译器会说些什么?
从:
let inds = [1; 2; 6; 8; 11; 12]
let vals = [10; 20; 30; 40; 50; 60]
为:
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]