我试着写在F#中的字符串处理函数,它看起来像这样:简单的办法
let rec Process html =
match html with
| '-' :: '-' :: '>' :: tail -> ("→" |> List.of_seq) @ Process tail
| head :: tail -> head :: Process tail
| [] -> []
我的模式对几个要素匹配表达式是有点难看(整个'-' :: '-' :: '>'
东西)。有什么办法可以让它变得更好吗?另外,如果我要处理大量文本,我的工作效率如何?还是有另一种方式?
澄清:我的意思是,例如,能够写出这样的事:
match html with
| "-->" :: tail ->
附注 - 我会使用过程而不是过程 - 命名空间冲突或程序员混淆的风险太大。看到这个问题:http://stackoverflow.com/questions/526930/f-naming-convention – Benjol 2009-02-23 08:27:29
感谢您的指针 - 将记住这一点。 – 2009-02-23 14:34:35
`警告FS0046:标识符'进程'保留供F#将来使用` – 2010-08-06 11:02:11