Skip to content

Instantly share code, notes, and snippets.

@jamii

jamii/after.imp Secret

Last active Oct 12, 2021
Embed
What would you like to do?
rightmost_child: edits.?edit edit parent~ @ max;
fix rightmost_leaf: edits.?edit edit | edit rightmost_child rightmost_leaf @ max;
prev_sibling: edits.?edit edit parent parent~ .(?sibling edit > sibling) @ max;
prev: edits.?edit edit prev_sibling !! then edit prev_sibling rightmost_leaf else edit parent;
fix position: root, 0 | position ?edit ?pos edit prev~, pos + 1;
edits ?edit (edit position), edit, (edit character)
let rightmost_child = edits (?edit . edit .
(max [edit ~parent])) in
let rightmost_leaf =
fix none (?[rightmost_leaf] .
edits (?edit . edit .
(max [edit | (edit rightmost_leaf rightmost_child)])))) in
let prev_sibling = edits (?edit . edit
(max [(edit parent ~parent) (?sibling . (when (edit > sibling) sibling))])) in
let prev = edits (?edit . edit .
if !!(prev_sibling edit)
([prev_sibling edit] max rightmost_leaf)
(edit parent)) in
let position =
fix none (?[position] .
edits (?edit . edit .
if !(edit parent) then 0 else
(edit prev position) + 1)) in
edits (?edit .
(edit position) . edit . (edit character))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment