1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556typet=stringexceptionBadofstringletraise_badmsg=raise(Badmsg)moduleSet=Char.Setletcodes=letcodes=['A';'C';'G';'T';'U';'R';'Y';'K';'M';'S';'W';'B';'D';'H';'V';'N';'X']inList.fold_left~f:(funse->Set.addse)~init:Set.emptycodesletis_nucleic_acidc=Set.memcodes(Char.uppercasec)lettoo_long=("sequence length exceeds "^(string_of_intCaml.Sys.max_string_length))letbad_acidc="invalid sequence element "^String.of_charcletof_bufferb=letn=Buffer.lengthbinifn>Caml.Sys.max_string_lengththenraise_badtoo_longelseletans=Bytes.createninfori=0ton-1doletc=Char.uppercase(Buffer.nthbi)inifis_nucleic_acidcthenBytes.setansicelseraise_bad(bad_acid(Buffer.nthbi))done;ansletof_stringb=letn=String.lengthbinletans=Bytes.createninfori=0ton-1doletc=Char.uppercaseb.[i]inifis_nucleic_acidcthenBytes.setansicelseraise_bad(bad_acidb.[i])done;ansletof_buffer_unsafeb=Buffer.contentsb|>String.uppercaseletof_string_unsafes=Bytes.copys|>String.uppercaseletto_string=Bytes.copyletnthti=String.gett(i-1)letlength=String.length(* FIXME: conform Core "t must come first" and have the same names *)letfold_leftfinits=String.folds~init~fletfold_leftifinits=String.foldis~init~f:(funiac->faic)(* FIXME: should have the same semantics as String.slice (otherwise
this is error prone). *)letslicefirstlastt=iffirst<1||last>String.lengtht||first>lastthenfailwith"requesting invalid slice from sequence"elseString.slicet(first-1)last