123456789101112131415161718192021222324252627282930openCore(*
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));;