クロージャで簡易ストリーム
もうイテレータはどうでもよくてAda.Containersをdisっているだけです。
O'Camlでよく見るスタイルを真似るのはどうでしょう。
let print_all (print : 'a -> unit) (next : unit -> 'a option): unit = ( match next () with | Some item -> print item; print_all print next | None -> () );; (* let input_from_stream s = let r = Stream.peek s; Stream.junk s; r *) print_all print_int (input_from_stream (Stream.of_list container))
generic type Element (<>) is limited private; with Put (Item : Element) is <>; procedure Generic_Put_All (Next : function return access constant Element) is Item : access constant Element := Next.all; begin if Item <> null then Put (Item.all); Put_All (Next); end if; end Put_All; declare Index : Cursor := First(Container); function Next is new Containers.Generic_Next (Container, Index); -- 実装略 function Put_All is new Generic_Put_All (Integer); begin Put_All (Next'Access); end;
input_from_streamだのGeneric_Nextだのはあらかじめライブラリ側で用意しておくとして、Adaで書いてもそんなに悪くない気がしませんか。