F# 액티브 패턴을 확장 된 튜플로 일치시킵니다
-
08-07-2019 - |
문제
서브 세트 아래에 빨간색 스쿼그가있는 Diff에서 다음 오류가 발생합니다.
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