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