【发布时间】:2013-05-05 10:56:32
【问题描述】:
如果我有以下功能:
let myFunc x y =
if y = 0 then 1
x
我得到错误:
Program.fs(58,17): error FS0001: This expression was expected to have type
unit
but here has type
int
为什么编译器期望 'unit' 而不是 int ?
【问题讨论】:
-
您将其标记为
if-statement的事实说明了 -- 在 F# 中,if是一个表达式。 :-] -
感谢狙击。
-
@ildjarn 虽然 F# 可能会将
if视为 表达式,但其他语言不会。仅仅为了 F# 对if的理解而有一个标签可能会给其他人带来很大的困惑......
标签: f# type-inference unit-type