我定义如下活动模式“表达”:如何将复杂表达式传递给参数化活动模式?
let (|Expression|_|) expression _ = Some(expression)
现在我想以这种方式来使用它:
match() with
| Expression((totalWidth - wLeft - wRight)/(float model.Columns.Count - 0.5)) cw
when cw <= wLeft * 4. && cw <= wRight * 4. ->
cw
| Expression((totalWidth - wLeft)/(float model.Columns.Count - .25)) cw
when cw <= wLeft * 4. && cw > wRight * 4. ->
cw
| Expression((totalWidth - wRight)/(float model.Columns.Count - .25)) cw
when cw > wLeft * 4. && cw <= wRight * 4. ->
cw
| Expression(totalWidth/float model.Columns.Count) cw
when cw > wLeft * 4. && cw > wRight * 4. ->
cw
| _ -> System.InvalidProgramException() |> raise
但是这会导致“错误FS0010:意外的符号“ - '模式'。这是可以修复的吗?
什么是我想要做的是写清楚了解决以下公式:
最大(WL - CW * 1.25,0)+ MAX(WR - CW * 0.25)+ CW *信息columnCount = ActualWidth
其中cw是唯一的变量。
你能提出任何更好的方法吗?
所以是不可能使用复合功能的主动模式的争论?例如我们不能做'| MyActive(myfuna >> myfunb)x - > ...'我们只能让'myfun = myfuna >> myfunb ... | MyActive myfun x - > ...' – colinfang 2013-01-24 21:13:51
是的,我认为这是正确的 - 你不能直接使用任何复杂的表达式。 – 2013-01-25 00:22:42