1234567891011121314151617181920212223242526272829openCore(* Creating a pad and adding a bunch of strings to it has asymtotic time and space
complexity O(n) where n is the total number of characters. Every once and a while,
there will be a very expensive [add] operation.
*)(** INVARIANT: strings are in order of decreasing length from right to left *)typet=|Empty|Snocoft*stringletempty=Emptyletrecaddtx=matchtwith|Empty->Snoc(Empty,x)|Snoc(rest,y)->ifString.lengthy>String.lengthxthenSnoc(t,x)elseaddrest(y^x);;letsingletonx=addemptyxletadd_chartc=addt(String.of_charc)letrecdump=function|Empty->""|Snoc(Empty,x)->x|Snoc(Snoc(t,x),y)->dump(Snoc(t,x^y));;