【发布时间】:2017-03-22 11:02:26
【问题描述】:
我正在浏览Hopac 文档,遇到了这个奇怪的类型错误:
let create x = Job.delay <| fun () ->
let c = {reqCh = Ch (); replyCh = Ch ()}
Job.iterateServer x <| fun x ->
c.reqCh >>= function
| Get -> c.replyCh *<- x >>-. x
| Put x -> Job.result x
>>-. c
Scrapers.SC.fsx(48,10): error FS0001: Type mismatch. Expecting a
''a'
but given a
'Cell<'a>'
The types ''a' and 'Cell<'a>' cannot be unified.
c 是一个Cell<'a>。此代码与页面中的代码编译得很好:
let create x = Job.delay <| fun () ->
let c = {reqCh = Ch (); replyCh = Ch ()}
Job.iterateServer x <| fun x ->
c.reqCh >>= function
| Get -> c.replyCh *<- x >>-. x
| Put x -> Job.result x
>>-. c
这两者之间的唯一区别是第一个缩进的深度 - 2 而不是 4。
通常,当缩进出现问题时,我会收到“可能不正确的缩进”警告,而不是类型错误。所以它一定是真的糊涂了。
我用F#十年了,还是不懂缩进规则。
我错过了什么?
【问题讨论】:
-
“我错过了什么?”对github.com/fsharp/fslang-suggestions/issues/470 点赞,这是修复当前令人困惑的规则的建议。 :-)
-
@rmunn 完成并完成。