我定義如下活動模式「表達」:如何將複雜表達式傳遞給參數化活動模式?
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