F# Printfn列表错误“;(a列表->;&x27;b列表)不兼容“;

F# Printfn列表错误“;(a列表->;&x27;b列表)不兼容“;,f#,F#,因此,我得到以下错误消息: The type '('a list -> 'b list)' is not compatible with any of the types byte,int16,int32,int64,sbyte,uint16,uint32,uint64,nativeint,unativeint, arising from the use of a printf-style format string 这是启动它的代码: let rec multC c = functi

因此,我得到以下错误消息:

The type '('a list -> 'b list)' is not compatible with any of the types
byte,int16,int32,int64,sbyte,uint16,uint32,uint64,nativeint,unativeint, 
arising from the use of a printf-style format string
这是启动它的代码:

let rec multC c = function
  | [] -> []
  | head::tail -> c * head::multC c tail


let p1 = [1; 2; 3];;
let resMultC = multC p1
printfn "resMultC: %d" resMultC

出于对我的爱,我无法理解为什么它不会打印出来,我想这就是错误的意思。有什么提示吗?

如果您在FSI中选中
multC
签名,它就是
c:int->\u arg1:int list->int list
。这意味着它需要两个参数(一个显式声明为
c
,另一个隐式声明为
函数
声明)

也就是说,代码的问题在于您只提供了一个参数

let resMultC = multC p1
而不是两个

let resMultC = multC 2 p1 // [2; 4; 6]
但即使现在,最后一个调用也无法编译,因为您正试图使用int格式设置程序(
%d
)打印列表。使用
%A
代替F#-特定类型:

printfn "resMultC: %A" resMultC // resMultC: [2; 4; 6]

multC
接受两个参数,您只提供了一个。也许会澄清…也许我误解了一些东西,但我不太确定我应该从您提供的链接中得到什么。
函数
比您可能想象的做得更多–特别是,它充当参数,使您的函数为二进制,而不是一元。很好,谢谢您的帮助。使用FSI检查是一个很好的技巧。