我正在关注斯科特的讲话,他带来的一个例子是:
type Result<'a> =
| Success of 'a
| Failure of string
let pchar (charToMatch, input) =
if System.String.IsNullOrEmpty (input) then
Failure "no input!"
else
let first = input.[0]
if first = charToMatch then
let remaining = input.[1..]
Success (charToMatch, remaining)
else
let msg = sprintf "exepecting '%c' got '%c'" charToMatch first
Failure msg
Run Code Online (Sandbox Code Playgroud)
Visual Studio代码显示该pchar函数的签名是:
char*string->Result<char*string> :
退货类型应该只是Result<'a>?
| 归档时间: |
|
| 查看次数: |
78 次 |
| 最近记录: |