F # مباراة نمط فاعلين الصفوف (tuple) توسيع
-
08-07-2019 - |
سؤال
وأحصل على الخطأ التالي في فرق مع تمايل الأحمر تحت الثانوية.
Type mismatch. Expecting a Range -> Choice but given a Range * Range -> Choice
هل هناك نوعا من نوع الشرح يمكنني أن أضيف إلى المباراة فرعية لذلك أنا لم يكن لديك لاستخدام FST وSND؟ إذا لم يكن هناك أي نية لدعم بناء الجملة هذا؟
type Range = {min : int64; max : int64}
let (|Before|After|BeforeOverlap|AfterOverlap|SuperSet|SubSet|) (x, y) =
if x.min > y.max then After
elif x.min >= y.min then
if x.max <= y.max then SubSet
else AfterOverlap
elif x.max < y.min then Before
elif x.max <= y.max then BeforeOverlap
else SuperSet
let useOldx x xe ye = ()
let diff (xe:IEnumerator<Range>) (ye:IEnumerator<Range>) =
match xe.Current, ye.Current with
| After as tuple -> ()
| Before as t -> if xe.MoveNext() then useOldx (fst t) xe ye
| SuperSet as t ->
let x, y = t
if xe.MoveNext() then useOldx x xe ye
| SubSet as x, y -> if xe.MoveNext() then useOldx x xe ye
| _ -> ()
المحلول
هل يمكن أن تفعل هذا:
| (x,y) & SubSet -> if xe.MoveNext() then useOldx x xe ye
وأو هل يمكن أن تفعل هذا:
open System.Collections.Generic
type Range = {min : int64; max : int64}
let (|Before|After|BeforeOverlap|AfterOverlap|SuperSet|SubSet|) (x, y) =
if x.min > y.max then After
elif x.min >= y.min then
if x.max <= y.max then SubSet(x,y)
else AfterOverlap
elif x.max < y.min then Before
elif x.max <= y.max then BeforeOverlap
else SuperSet
let useOldx x xe ye = ()
let diff (xe:IEnumerator<Range>) (ye:IEnumerator<Range>) =
match xe.Current, ye.Current with
| After as tuple -> ()
| Before as t -> if xe.MoveNext() then useOldx (fst t) xe ye
| SuperSet as t ->
let x, y = t
if xe.MoveNext() then useOldx x xe ye
| SubSet(x, y) -> if xe.MoveNext() then useOldx x xe ye
| _ -> ()
لا تنتمي إلى StackOverflow