F # corrisponde al modello attivo come tupla espansa
-
08-07-2019 - |
Domanda
Ottengo il seguente errore in diff con uno squiggle rosso in Sottoinsieme.
Tipo non corrispondente. Aspettando un intervallo - > Scelta ma data una gamma * Range - > Scelta ??code>
Esiste una sorta di annotazione del tipo che posso aggiungere alla corrispondenza del sottoinsieme, quindi non devo usare fst e snd? In caso contrario, vi è alcuna intenzione di supportare questa sintassi?
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
| _ -> ()
Soluzione
Puoi farlo:
| (x,y) & SubSet -> if xe.MoveNext() then useOldx x xe ye
oppure potresti farlo:
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
| _ -> ()
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow