1234567891011121314151617181920212223242526272829303132333435363738394041424344openCore_kernelopenDeferred_stdmoduleList=Deferred_list(* We implement all of the [Queue] operations by converting the queue to a list and then
using the corresponding [List] operation. We use lists rather than arrays because
arrays longer than a certain length are allocated in the major heap, which can cause
unnecessary promotion of the elements in the queue. Also, when one is folding or
iterating over an array, the entire array must be kept alive. When folding or
iterating over a list, only the remaining tail of the list is kept alive. So, using
arrays rather than lists would increase the live-space needed by the program. *)letfoldit~init~f=List.foldi(Queue.to_listt)~init~fletfoldt~init~f=List.fold(Queue.to_listt)~init~fletallt=List.all(Queue.to_listt)>>|Queue.of_listletall_unitt=List.all_unit(Queue.to_listt)letiter?howt~f=List.iter?how(Queue.to_listt)~fletiteri?howt~f=List.iteri?how(Queue.to_listt)~fletmap?howt~f=List.map?how(Queue.to_listt)~f>>|Queue.of_listletmapi?howt~f=List.mapi?how(Queue.to_listt)~f>>|Queue.of_listletinit?hown~f=List.init?hown~f>>|Queue.of_listletfilter?howt~f=List.filter?how(Queue.to_listt)~f>>|Queue.of_listletfilteri?howt~f=List.filteri?how(Queue.to_listt)~f>>|Queue.of_listletfilter_map?howt~f=List.filter_map?how(Queue.to_listt)~f>>|Queue.of_listletfilter_mapi?howt~f=List.filter_mapi?how(Queue.to_listt)~f>>|Queue.of_listletconcat_map?howt~f=List.concat_map?how(Queue.to_listt)~f:(funx->fx>>|Queue.to_list)>>|Queue.of_list;;letconcat_mapi?howt~f=List.concat_mapi?how(Queue.to_listt)~f:(funix->fix>>|Queue.to_list)>>|Queue.of_list;;letfind_mapt~f=List.find_map(Queue.to_listt)~fletfind_mapit~f=List.find_mapi(Queue.to_listt)~fletfindt~f=List.find(Queue.to_listt)~fletfindit~f=List.findi(Queue.to_listt)~fletfor_allt~f=List.for_all(Queue.to_listt)~fletfor_allit~f=List.for_alli(Queue.to_listt)~fletexistst~f=List.exists(Queue.to_listt)~fletexistsit~f=List.existsi(Queue.to_listt)~f