fact: Definition remove (e:E) (t:tree) : tree := match locate e t Top_c with | inl _ => t | inr (_, loc) => match loc with | TwoHole_l tl tr c => let mkContext g c' := TwoLeftHole_c g tr c' in match locateGreatest tl Top_c with | None => removeUp Null_t c | Some (g, inl c') => removeUp Null_t $ fuse (mkContext g c') c | Some (g, inr (el, c')) => zip (single el) $ fuse (mkContext g c') c end | ThreeLeftHole_l tl tm er tr c => let mkContext g c' := ThreeLeftHole_c g tm er tr c' in match locateGreatest tl Top_c with | None => zip (single er) c | Some (g, inl c') => removeUp Null_t $ fuse (mkContext g c') c | Some (g, inr (el, c')) => zip (single el) $ fuse (mkContext g c') c end | ThreeRightHole_l tl el tm tr c => let mkContext g c' := ThreeMiddleHole_c tl el g tr c' in match locateGreatest tm Top_c with | None => zip (single el) c | Some (g, inl c') => removeUp Null_t $ fuse (mkContext g c') c | Some (g, inr (el, c')) => zip (single el) $ fuse (mkContext g c') c end end end.
imports: ExtLib.Structures.Monads ExtLib.Data.Monads.OptionMonad ExtLib.Programming.Extras