Diffing_with_keys(3)
π NAME
okay so bestie, welcome to the Diffing_with_keys(3) page from the OCaml library β¨. It's literally about when you're diffing lists where each element has a distinct key, and we can refine the diffing patch by introducing two composite edit moves: swaps and moves. it's giving refined-patch energy, fr fr.
π§ Module
okay the module itself is Module Diffing_with_keys and it's just:
Module Diffing_with_keys : sig end
no cap, that's the whole signature vibe check π .
β¨ Documentation
okay so Module Diffing_with_keys is right here:
Module Diffing_with_keys : sig end
When diffing lists where each element has a distinct key, we can refine the diffing patch by introducing two composite edit moves: swaps and moves.
Swaps exchange the position of two elements. Swap cost is set to 2 * change - epsilon.
Moves change the position of one element. Move cost is set to delete + addition - epsilon.
When the cost delete + addition is greater than change and with those specific weights, the optimal patch with Swaps and Moves can be computed directly and cheaply from the original optimal patch.
here's the with_pos situation, bestie π:
type 'a with_pos = {
pos : int ;
data : 'a ;
}
and the val:
val with_pos : 'a list -> 'a with_pos list
then we got the mismatch type, which is giving "whoops that's not it" energy π:
type ('l, 'r, 'diff) mismatch =
| Name of {
pos : int ;
got : string ;
expected : string ;
types_match : bool ;
}
| Type of {
pos : int ;
got : 'l ;
expected : 'r ;
reason : 'diff ;
}
and the change type, the main character of the whole page π:
type ('l, 'r, 'diff) change =
| Change of ('l, 'r, 'diff) mismatch
| Swap of {
pos : int * int ;
first : string ;
last : string ;
}
| Move of {
name : string ;
got : int ;
expected : int ;
}
| Insert of {
pos : int ;
insert : 'r ;
}
| Delete of {
pos : int ;
delete : 'l ;
}
This specialized version of changes introduces two composite changes: Move and Swap β¨.
also prefix is right here:
val prefix : ('l, 'r, 'diff) change Format_doc.printer
and Define is like:
module Define : (D : sig end) -> sig end
bestie reminder: every type, field, constructor, val, module signature, and cost formula above is exactly the technical tea β don't rename or merge anything, okay? π«Ά
mwah π that's the whole page! it came from OCamldoc, version/date 2026-06-22, and it was Diffing_with_keys(3) the entire time. periodt. π
π¦ where this page comes from
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms