有没有将调用嵌套到活动模式的方法?有没有办法将调用嵌套到F#活动模式?
事情是这样的:
type Fnord =
| Foo of int
let (|IsThree|IsNotThree|) x =
match x with
| x when x = 3 -> IsThree
| _ -> IsNotThree
let q n =
match n with
| Foo x ->
match x with
| IsThree -> true
| IsNotThree -> false
// Is there a more ideomatic way to write the previous
// 5 lines? Something like:
// match n with
// | IsThree(Foo x) -> true
// | IsNotThree(Foo x) -> false
let r = q (Foo 3) // want this to be false
let s = q (Foo 4) // want this to be true
或者是跟其他比赛对手的首选方式去?
+1为Fnord。 – bmargulies 2010-01-04 01:14:43
该死的语言是不可读的。认真 - Python能做什么? – 2010-01-04 01:24:14
@lpthnc:模式匹配? – Chuck 2010-01-04 01:35:38