小编uhr*_*hrm的帖子

F#(.. ..)运算符使用/重载

我有兴趣使用/重载"范围步骤"操作符(.. ..),但我不能为我的生活找到如何使用它.

在文档中说

// Usage:
start .. step .. finish
Run Code Online (Sandbox Code Playgroud)

但是在F#shell中尝试它会产生错误:

> let x = 1 .. 2 .. 7;;

  let x = 1 .. 2 .. 7;;
  ----------^^

stdin(54,11): error FS0010: Unexpected symbol '..' in binding. Expected incomplete structured construct at or before this point or other token.
Run Code Online (Sandbox Code Playgroud)

但是,可以"明确地"调用它:

> let x = (.. ..) 1 2 7;;

val x : seq<int>
Run Code Online (Sandbox Code Playgroud)

是否只能将此运算符用于列表/ seq构造,例如[1..2..7]seq {1..2..7}

f# operator-overloading

5
推荐指数
1
解决办法
411
查看次数

标签 统计

f# ×1

operator-overloading ×1