【问题标题】:Error: This expression was expected to have type byte [] but here has type 'a * 'b * 'c" in F#错误:此表达式应具有类型 byte [] 但此处在 F# 中具有类型 'a * 'b * 'c"
【发布时间】:2015-07-22 18:19:48
【问题描述】:
   let IndexOf (searchWithin:byte[])(searchFor:byte[])(startIndex:int):(int) =
      //Function defination
   0

   //calling thisfunction using below
   let endIndex = IndexOf(data, delimiterBytes, startIndex)

   //data is type of byte[], delimiterBytes is also type of byte[] and 
   //startIndex is type of interger.

我收到错误消息,例如“此表达式的类型应为字节 [],但此处的类型为 'a * 'b * 'c”。我不明白 'a * 'b * 'c 的含义以及为什么它会显示错误。谢谢。

【问题讨论】:

  • 您使用的是柯里化形式而不是元组形式。这注定是重复的
  • 如何在“IndexOf”函数中使用元组形式?

标签: function f# f#-3.0


【解决方案1】:

问题是你的函数定义是所谓的柯里化形式

let t a b c = ...

需要这样使用:

t 1 2 3

您可以将声明更改为元组形式

let t (a,b,c) = ...

或将用法更改为

t 1 2 3

这是柯里化的形式。

有关差异的更多信息,请参见此处:F# parameter passing

【讨论】:

  • 谢谢 .. 我试过了,它工作正常。你能告诉我 let t (a,b,c) 和 let t(a)(b)(c) 有什么不同吗?
  • 谢谢。现在很清楚了。 t(a)(b)(c) 和 t a b c 都一样不一样?
  • 这两种形式是一样的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多