アクティブパターン「式」を次のように定義しました。
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:パターン内の予期しないシンボル'-'」が発生します。それは修正可能ですか?
私がやろうとしているのは、次の方程式の解を明確に書くことです。
max(wl --cw * .25、0)+ max(wr --cw * .25)+ cw * columnCount = ActualWidth
ここで、cwは唯一の変数です。
もっと良い方法を提案できますか?