【发布时间】:2014-12-22 20:06:10
【问题描述】:
以下 sn-p 说明了我遇到的错误。即使两个匹配分支都返回相同的东西;我得到错误,“这个表达式应该有单位类型,但这里有类型'a - >单位”我不知道编译器在这里想要什么......
open System.IO
let FileContent contents =
match contents with
| "" -> None
| c -> Some(c)
let WriteSomething (contents:string) =
let writer = new StreamWriter("")
writer.Write( contents ) |> ignore
let DoStuffWithFileContents =
let reader = new StreamReader( "" )
let stuff = reader.ReadToEnd()
match stuff |> FileContent with
| Some(c) -> WriteSomething c
|> ignore
| None -> ignore // <- error on "ignore"
【问题讨论】: