【发布时间】:2014-08-31 11:20:29
【问题描述】:
我有以下解析整数的函数:
let rec digits = function
| head::tail when System.Char.IsDigit(head) ->
let result = digits tail
(head::(fst result), snd result)
| rest -> ([], rest)
如果我将此函数更改为主动识别器,它将不再编译。
let rec (|Digits|) = function
| head::tail when System.Char.IsDigit(head) ->
let result = Digits tail
(head::(fst result), snd result)
// ^^^^^^ ^^^^^^ see error*
| rest -> ([], rest)
*error FS0001: 这个表达式应该有类型 char list * 'a 但这里有类型 字符列表
【问题讨论】:
标签: parsing f# metaprogramming