Permalink
Browse files

Stream: fixed confusing on the semantic of indexed iterators

indexed iterators (iteri, foldi, iter2i, fold2i, ...) expect a
function that itself expects an integer. I was confused between two
semantics:
- either this integer corresponds to the number of times the function
was called
- either it corresponds to the index of the element in the stream.

I chose the second semantic as it seems more informative to me.
  • Loading branch information...
1 parent df6a4be commit e6d6fc191bebf0bb8238d6119803e81cb834fdf2 @pveber pveber committed with agarwal Nov 17, 2012
Showing with 115 additions and 789 deletions.
  1. +0 −183 _tags
  2. +0 −497 myocamlbuild.ml
  3. +98 −100 src/lib/biocaml_internal_pervasives.ml
  4. +17 −9 src/lib/biocaml_internal_pervasives.mli
View
183 _tags
@@ -1,187 +1,4 @@
# OASIS_START
-# DO NOT EDIT (digest: d257414835eec2ab82756b5e4dc4e548)
-# Ignore VCS directories, you can use the same kind of rule outside
-# OASIS_START/STOP if you want to exclude directories that contains
-# useless stuff for the build process
-<**/.svn>: -traverse
-<**/.svn>: not_hygienic
-".bzr": -traverse
-".bzr": not_hygienic
-".hg": -traverse
-".hg": not_hygienic
-".git": -traverse
-".git": not_hygienic
-"_darcs": -traverse
-"_darcs": not_hygienic
-# Library biocaml
-"src/lib/biocaml.cmxs": use_biocaml
-<src/lib/*.ml{,i}>: oasis_library_biocaml_ccopt
-"src/lib/biocaml_pwm_stub.c": oasis_library_biocaml_ccopt
-"src/lib/biocaml_mzData_stubs.c": oasis_library_biocaml_ccopt
-<src/lib/biocaml.{cma,cmxa}>: use_libbiocaml_stubs
-<src/lib/*.ml{,i}>: pkg_threads
-<src/lib/*.ml{,i}>: pkg_unix
-<src/lib/*.ml{,i}>: pkg_batteries
-<src/lib/*.ml{,i}>: pkg_core
-<src/lib/*.ml{,i}>: pkg_sexplib.syntax
-<src/lib/*.ml{,i}>: pkg_zip
-<src/lib/*.ml{,i}>: pkg_sqlite3
-<src/lib/*.ml{,i}>: pkg_xmlm
-<src/lib/*.ml{,i}>: pkg_pcre
-"src/lib/biocaml_pwm_stub.c": pkg_threads
-"src/lib/biocaml_pwm_stub.c": pkg_unix
-"src/lib/biocaml_pwm_stub.c": pkg_batteries
-"src/lib/biocaml_pwm_stub.c": pkg_core
-"src/lib/biocaml_pwm_stub.c": pkg_sexplib.syntax
-"src/lib/biocaml_pwm_stub.c": pkg_zip
-"src/lib/biocaml_pwm_stub.c": pkg_sqlite3
-"src/lib/biocaml_pwm_stub.c": pkg_xmlm
-"src/lib/biocaml_pwm_stub.c": pkg_pcre
-"src/lib/biocaml_mzData_stubs.c": pkg_threads
-"src/lib/biocaml_mzData_stubs.c": pkg_unix
-"src/lib/biocaml_mzData_stubs.c": pkg_batteries
-"src/lib/biocaml_mzData_stubs.c": pkg_core
-"src/lib/biocaml_mzData_stubs.c": pkg_sexplib.syntax
-"src/lib/biocaml_mzData_stubs.c": pkg_zip
-"src/lib/biocaml_mzData_stubs.c": pkg_sqlite3
-"src/lib/biocaml_mzData_stubs.c": pkg_xmlm
-"src/lib/biocaml_mzData_stubs.c": pkg_pcre
-# Executable gff_counts
-<src/app/gff_counts.{native,byte}>: use_biocaml
-<src/app/gff_counts.{native,byte}>: pkg_threads
-<src/app/gff_counts.{native,byte}>: pkg_unix
-<src/app/gff_counts.{native,byte}>: pkg_batteries
-<src/app/gff_counts.{native,byte}>: pkg_getopt
-<src/app/gff_counts.{native,byte}>: pkg_core
-<src/app/gff_counts.{native,byte}>: pkg_sexplib.syntax
-<src/app/gff_counts.{native,byte}>: pkg_zip
-<src/app/gff_counts.{native,byte}>: pkg_sqlite3
-<src/app/gff_counts.{native,byte}>: pkg_xmlm
-<src/app/gff_counts.{native,byte}>: pkg_pcre
-# Executable gff_to_bed
-<src/app/gff_to_bed.{native,byte}>: use_biocaml
-<src/app/gff_to_bed.{native,byte}>: pkg_threads
-<src/app/gff_to_bed.{native,byte}>: pkg_unix
-<src/app/gff_to_bed.{native,byte}>: pkg_batteries
-<src/app/gff_to_bed.{native,byte}>: pkg_getopt
-<src/app/gff_to_bed.{native,byte}>: pkg_core
-<src/app/gff_to_bed.{native,byte}>: pkg_sexplib.syntax
-<src/app/gff_to_bed.{native,byte}>: pkg_zip
-<src/app/gff_to_bed.{native,byte}>: pkg_sqlite3
-<src/app/gff_to_bed.{native,byte}>: pkg_xmlm
-<src/app/gff_to_bed.{native,byte}>: pkg_pcre
-# Executable gff_to_table
-<src/app/gff_to_table.{native,byte}>: use_biocaml
-<src/app/gff_to_table.{native,byte}>: pkg_threads
-<src/app/gff_to_table.{native,byte}>: pkg_unix
-<src/app/gff_to_table.{native,byte}>: pkg_batteries
-<src/app/gff_to_table.{native,byte}>: pkg_getopt
-<src/app/gff_to_table.{native,byte}>: pkg_core
-<src/app/gff_to_table.{native,byte}>: pkg_sexplib.syntax
-<src/app/gff_to_table.{native,byte}>: pkg_zip
-<src/app/gff_to_table.{native,byte}>: pkg_sqlite3
-<src/app/gff_to_table.{native,byte}>: pkg_xmlm
-<src/app/gff_to_table.{native,byte}>: pkg_pcre
-# Executable sgr_to_wig
-<src/app/sgr_to_wig.{native,byte}>: use_biocaml
-<src/app/sgr_to_wig.{native,byte}>: pkg_threads
-<src/app/sgr_to_wig.{native,byte}>: pkg_unix
-<src/app/sgr_to_wig.{native,byte}>: pkg_batteries
-<src/app/sgr_to_wig.{native,byte}>: pkg_getopt
-<src/app/sgr_to_wig.{native,byte}>: pkg_core
-<src/app/sgr_to_wig.{native,byte}>: pkg_sexplib.syntax
-<src/app/sgr_to_wig.{native,byte}>: pkg_zip
-<src/app/sgr_to_wig.{native,byte}>: pkg_sqlite3
-<src/app/sgr_to_wig.{native,byte}>: pkg_xmlm
-<src/app/sgr_to_wig.{native,byte}>: pkg_pcre
-# Executable wig_correlate
-<src/app/wig_correlate.{native,byte}>: use_biocaml
-<src/app/wig_correlate.{native,byte}>: pkg_threads
-<src/app/wig_correlate.{native,byte}>: pkg_unix
-<src/app/wig_correlate.{native,byte}>: pkg_batteries
-<src/app/wig_correlate.{native,byte}>: pkg_getopt
-<src/app/wig_correlate.{native,byte}>: pkg_core
-<src/app/wig_correlate.{native,byte}>: pkg_sexplib.syntax
-<src/app/wig_correlate.{native,byte}>: pkg_zip
-<src/app/wig_correlate.{native,byte}>: pkg_sqlite3
-<src/app/wig_correlate.{native,byte}>: pkg_xmlm
-<src/app/wig_correlate.{native,byte}>: pkg_pcre
-<src/app/*.ml{,i}>: pkg_getopt
-# Executable biocaml
-<src/app/biocaml_main.{native,byte}>: use_biocaml
-<src/app/biocaml_main.{native,byte}>: pkg_lwt.unix
-<src/app/biocaml_main.{native,byte}>: pkg_core_extended
-<src/app/biocaml_main.{native,byte}>: pkg_threads
-<src/app/biocaml_main.{native,byte}>: pkg_unix
-<src/app/biocaml_main.{native,byte}>: pkg_batteries
-<src/app/biocaml_main.{native,byte}>: pkg_lwt
-<src/app/biocaml_main.{native,byte}>: pkg_core
-<src/app/biocaml_main.{native,byte}>: pkg_sexplib.syntax
-<src/app/biocaml_main.{native,byte}>: pkg_zip
-<src/app/biocaml_main.{native,byte}>: pkg_sqlite3
-<src/app/biocaml_main.{native,byte}>: pkg_xmlm
-<src/app/biocaml_main.{native,byte}>: pkg_pcre
-<src/app/*.ml{,i}>: use_biocaml
-<src/app/*.ml{,i}>: pkg_lwt.unix
-<src/app/*.ml{,i}>: pkg_core_extended
-<src/app/*.ml{,i}>: pkg_threads
-<src/app/*.ml{,i}>: pkg_unix
-<src/app/*.ml{,i}>: pkg_batteries
-<src/app/*.ml{,i}>: pkg_lwt
-<src/app/*.ml{,i}>: pkg_core
-<src/app/*.ml{,i}>: pkg_sexplib.syntax
-<src/app/*.ml{,i}>: pkg_zip
-<src/app/*.ml{,i}>: pkg_sqlite3
-<src/app/*.ml{,i}>: pkg_xmlm
-<src/app/*.ml{,i}>: pkg_pcre
-# Executable tests_main
-"src/tests/main.native": use_biocaml
-"src/tests/main.native": pkg_threads
-"src/tests/main.native": pkg_unix
-"src/tests/main.native": pkg_oUnit
-"src/tests/main.native": pkg_batteries
-"src/tests/main.native": pkg_core
-"src/tests/main.native": pkg_sexplib.syntax
-"src/tests/main.native": pkg_zip
-"src/tests/main.native": pkg_sqlite3
-"src/tests/main.native": pkg_xmlm
-"src/tests/main.native": pkg_pcre
-<src/tests/*.ml{,i}>: use_biocaml
-<src/tests/*.ml{,i}>: pkg_threads
-<src/tests/*.ml{,i}>: pkg_unix
-<src/tests/*.ml{,i}>: pkg_oUnit
-<src/tests/*.ml{,i}>: pkg_batteries
-<src/tests/*.ml{,i}>: pkg_core
-<src/tests/*.ml{,i}>: pkg_sexplib.syntax
-<src/tests/*.ml{,i}>: pkg_zip
-<src/tests/*.ml{,i}>: pkg_sqlite3
-<src/tests/*.ml{,i}>: pkg_xmlm
-<src/tests/*.ml{,i}>: pkg_pcre
-# Executable lwt_tests
-"src/lwt_tests/main.native": use_biocaml
-"src/lwt_tests/main.native": pkg_lwt.unix
-"src/lwt_tests/main.native": pkg_core_extended
-"src/lwt_tests/main.native": pkg_threads
-"src/lwt_tests/main.native": pkg_unix
-"src/lwt_tests/main.native": pkg_batteries
-"src/lwt_tests/main.native": pkg_core
-"src/lwt_tests/main.native": pkg_sexplib.syntax
-"src/lwt_tests/main.native": pkg_zip
-"src/lwt_tests/main.native": pkg_sqlite3
-"src/lwt_tests/main.native": pkg_xmlm
-"src/lwt_tests/main.native": pkg_pcre
-<src/lwt_tests/*.ml{,i}>: use_biocaml
-<src/lwt_tests/*.ml{,i}>: pkg_lwt.unix
-<src/lwt_tests/*.ml{,i}>: pkg_core_extended
-<src/lwt_tests/*.ml{,i}>: pkg_threads
-<src/lwt_tests/*.ml{,i}>: pkg_unix
-<src/lwt_tests/*.ml{,i}>: pkg_batteries
-<src/lwt_tests/*.ml{,i}>: pkg_core
-<src/lwt_tests/*.ml{,i}>: pkg_sexplib.syntax
-<src/lwt_tests/*.ml{,i}>: pkg_zip
-<src/lwt_tests/*.ml{,i}>: pkg_sqlite3
-<src/lwt_tests/*.ml{,i}>: pkg_xmlm
-<src/lwt_tests/*.ml{,i}>: pkg_pcre
# OASIS_STOP
<src/*/*.ml{,i}>: syntax_camlp4o
View
497 myocamlbuild.ml
@@ -1,502 +1,5 @@
(* OASIS_START *)
-(* DO NOT EDIT (digest: c085f2e2c5bc004ca0f76bc5fcbe9a85) *)
-module OASISGettext = struct
-# 21 "/home/pveber/.opam/4.00.1/build/oasis.0.3.0/src/oasis/OASISGettext.ml"
-
- let ns_ str =
- str
-
- let s_ str =
- str
-
- let f_ (str : ('a, 'b, 'c, 'd) format4) =
- str
-
- let fn_ fmt1 fmt2 n =
- if n = 1 then
- fmt1^^""
- else
- fmt2^^""
-
- let init =
- []
-
-end
-
-module OASISExpr = struct
-# 21 "/home/pveber/.opam/4.00.1/build/oasis.0.3.0/src/oasis/OASISExpr.ml"
-
-
-
- open OASISGettext
-
- type test = string
-
- type flag = string
-
- type t =
- | EBool of bool
- | ENot of t
- | EAnd of t * t
- | EOr of t * t
- | EFlag of flag
- | ETest of test * string
-
-
- type 'a choices = (t * 'a) list
-
- let eval var_get t =
- let rec eval' =
- function
- | EBool b ->
- b
-
- | ENot e ->
- not (eval' e)
-
- | EAnd (e1, e2) ->
- (eval' e1) && (eval' e2)
-
- | EOr (e1, e2) ->
- (eval' e1) || (eval' e2)
-
- | EFlag nm ->
- let v =
- var_get nm
- in
- assert(v = "true" || v = "false");
- (v = "true")
-
- | ETest (nm, vl) ->
- let v =
- var_get nm
- in
- (v = vl)
- in
- eval' t
-
- let choose ?printer ?name var_get lst =
- let rec choose_aux =
- function
- | (cond, vl) :: tl ->
- if eval var_get cond then
- vl
- else
- choose_aux tl
- | [] ->
- let str_lst =
- if lst = [] then
- s_ "<empty>"
- else
- String.concat
- (s_ ", ")
- (List.map
- (fun (cond, vl) ->
- match printer with
- | Some p -> p vl
- | None -> s_ "<no printer>")
- lst)
- in
- match name with
- | Some nm ->
- failwith
- (Printf.sprintf
- (f_ "No result for the choice list '%s': %s")
- nm str_lst)
- | None ->
- failwith
- (Printf.sprintf
- (f_ "No result for a choice list: %s")
- str_lst)
- in
- choose_aux (List.rev lst)
-
-end
-
-
-# 117 "myocamlbuild.ml"
-module BaseEnvLight = struct
-# 21 "/home/pveber/.opam/4.00.1/build/oasis.0.3.0/src/base/BaseEnvLight.ml"
-
- module MapString = Map.Make(String)
-
- type t = string MapString.t
-
- let default_filename =
- Filename.concat
- (Sys.getcwd ())
- "setup.data"
-
- let load ?(allow_empty=false) ?(filename=default_filename) () =
- if Sys.file_exists filename then
- begin
- let chn =
- open_in_bin filename
- in
- let st =
- Stream.of_channel chn
- in
- let line =
- ref 1
- in
- let st_line =
- Stream.from
- (fun _ ->
- try
- match Stream.next st with
- | '\n' -> incr line; Some '\n'
- | c -> Some c
- with Stream.Failure -> None)
- in
- let lexer =
- Genlex.make_lexer ["="] st_line
- in
- let rec read_file mp =
- match Stream.npeek 3 lexer with
- | [Genlex.Ident nm; Genlex.Kwd "="; Genlex.String value] ->
- Stream.junk lexer;
- Stream.junk lexer;
- Stream.junk lexer;
- read_file (MapString.add nm value mp)
- | [] ->
- mp
- | _ ->
- failwith
- (Printf.sprintf
- "Malformed data file '%s' line %d"
- filename !line)
- in
- let mp =
- read_file MapString.empty
- in
- close_in chn;
- mp
- end
- else if allow_empty then
- begin
- MapString.empty
- end
- else
- begin
- failwith
- (Printf.sprintf
- "Unable to load environment, the file '%s' doesn't exist."
- filename)
- end
-
- let var_get name env =
- let rec var_expand str =
- let buff =
- Buffer.create ((String.length str) * 2)
- in
- Buffer.add_substitute
- buff
- (fun var ->
- try
- var_expand (MapString.find var env)
- with Not_found ->
- failwith
- (Printf.sprintf
- "No variable %s defined when trying to expand %S."
- var
- str))
- str;
- Buffer.contents buff
- in
- var_expand (MapString.find name env)
-
- let var_choose lst env =
- OASISExpr.choose
- (fun nm -> var_get nm env)
- lst
-end
-
-
-# 215 "myocamlbuild.ml"
-module MyOCamlbuildFindlib = struct
-# 21 "/home/pveber/.opam/4.00.1/build/oasis.0.3.0/src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml"
-
- (** OCamlbuild extension, copied from
- * http://brion.inria.fr/gallium/index.php/Using_ocamlfind_with_ocamlbuild
- * by N. Pouillard and others
- *
- * Updated on 2009/02/28
- *
- * Modified by Sylvain Le Gall
- *)
- open Ocamlbuild_plugin
-
- (* these functions are not really officially exported *)
- let run_and_read =
- Ocamlbuild_pack.My_unix.run_and_read
-
- let blank_sep_strings =
- Ocamlbuild_pack.Lexers.blank_sep_strings
-
- let split s ch =
- let x =
- ref []
- in
- let rec go s =
- let pos =
- String.index s ch
- in
- x := (String.before s pos)::!x;
- go (String.after s (pos + 1))
- in
- try
- go s
- with Not_found -> !x
-
- let split_nl s = split s '\n'
-
- let before_space s =
- try
- String.before s (String.index s ' ')
- with Not_found -> s
-
- (* this lists all supported packages *)
- let find_packages () =
- List.map before_space (split_nl & run_and_read "ocamlfind list")
-
- (* this is supposed to list available syntaxes, but I don't know how to do it. *)
- let find_syntaxes () = ["camlp4o"; "camlp4r"]
-
- (* ocamlfind command *)
- let ocamlfind x = S[A"ocamlfind"; x]
-
- let dispatch =
- function
- | Before_options ->
- (* by using Before_options one let command line options have an higher priority *)
- (* on the contrary using After_options will guarantee to have the higher priority *)
- (* override default commands by ocamlfind ones *)
- Options.ocamlc := ocamlfind & A"ocamlc";
- Options.ocamlopt := ocamlfind & A"ocamlopt";
- Options.ocamldep := ocamlfind & A"ocamldep";
- Options.ocamldoc := ocamlfind & A"ocamldoc";
- Options.ocamlmktop := ocamlfind & A"ocamlmktop"
-
- | After_rules ->
-
- (* When one link an OCaml library/binary/package, one should use -linkpkg *)
- flag ["ocaml"; "link"; "program"] & A"-linkpkg";
-
- (* For each ocamlfind package one inject the -package option when
- * compiling, computing dependencies, generating documentation and
- * linking. *)
- List.iter
- begin fun pkg ->
- flag ["ocaml"; "compile"; "pkg_"^pkg] & S[A"-package"; A pkg];
- flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S[A"-package"; A pkg];
- flag ["ocaml"; "doc"; "pkg_"^pkg] & S[A"-package"; A pkg];
- flag ["ocaml"; "link"; "pkg_"^pkg] & S[A"-package"; A pkg];
- flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S[A"-package"; A pkg];
- end
- (find_packages ());
-
- (* Like -package but for extensions syntax. Morover -syntax is useless
- * when linking. *)
- List.iter begin fun syntax ->
- flag ["ocaml"; "compile"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
- flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
- flag ["ocaml"; "doc"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
- flag ["ocaml"; "infer_interface"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
- end (find_syntaxes ());
-
- (* The default "thread" tag is not compatible with ocamlfind.
- * Indeed, the default rules add the "threads.cma" or "threads.cmxa"
- * options when using this tag. When using the "-linkpkg" option with
- * ocamlfind, this module will then be added twice on the command line.
- *
- * To solve this, one approach is to add the "-thread" option when using
- * the "threads" package using the previous plugin.
- *)
- flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]);
- flag ["ocaml"; "pkg_threads"; "doc"] (S[A "-I"; A "+threads"]);
- flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]);
- flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"])
-
- | _ ->
- ()
-
-end
-
-module MyOCamlbuildBase = struct
-# 21 "/home/pveber/.opam/4.00.1/build/oasis.0.3.0/src/plugins/ocamlbuild/MyOCamlbuildBase.ml"
-
- (** Base functions for writing myocamlbuild.ml
- @author Sylvain Le Gall
- *)
-
-
-
- open Ocamlbuild_plugin
- module OC = Ocamlbuild_pack.Ocaml_compiler
-
- type dir = string
- type file = string
- type name = string
- type tag = string
-
-# 56 "/home/pveber/.opam/4.00.1/build/oasis.0.3.0/src/plugins/ocamlbuild/MyOCamlbuildBase.ml"
-
- type t =
- {
- lib_ocaml: (name * dir list) list;
- lib_c: (name * dir * file list) list;
- flags: (tag list * (spec OASISExpr.choices)) list;
- (* Replace the 'dir: include' from _tags by a precise interdepends in
- * directory.
- *)
- includes: (dir * dir list) list;
- }
-
- let env_filename =
- Pathname.basename
- BaseEnvLight.default_filename
-
- let dispatch_combine lst =
- fun e ->
- List.iter
- (fun dispatch -> dispatch e)
- lst
-
- let tag_libstubs nm =
- "use_lib"^nm^"_stubs"
-
- let nm_libstubs nm =
- nm^"_stubs"
-
- let dispatch t e =
- let env =
- BaseEnvLight.load
- ~filename:env_filename
- ~allow_empty:true
- ()
- in
- match e with
- | Before_options ->
- let no_trailing_dot s =
- if String.length s >= 1 && s.[0] = '.' then
- String.sub s 1 ((String.length s) - 1)
- else
- s
- in
- List.iter
- (fun (opt, var) ->
- try
- opt := no_trailing_dot (BaseEnvLight.var_get var env)
- with Not_found ->
- Printf.eprintf "W: Cannot get variable %s" var)
- [
- Options.ext_obj, "ext_obj";
- Options.ext_lib, "ext_lib";
- Options.ext_dll, "ext_dll";
- ]
-
- | After_rules ->
- (* Declare OCaml libraries *)
- List.iter
- (function
- | nm, [] ->
- ocaml_lib nm
- | nm, dir :: tl ->
- ocaml_lib ~dir:dir (dir^"/"^nm);
- List.iter
- (fun dir ->
- List.iter
- (fun str ->
- flag ["ocaml"; "use_"^nm; str] (S[A"-I"; P dir]))
- ["compile"; "infer_interface"; "doc"])
- tl)
- t.lib_ocaml;
-
- (* Declare directories dependencies, replace "include" in _tags. *)
- List.iter
- (fun (dir, include_dirs) ->
- Pathname.define_context dir include_dirs)
- t.includes;
-
- (* Declare C libraries *)
- List.iter
- (fun (lib, dir, headers) ->
- (* Handle C part of library *)
- flag ["link"; "library"; "ocaml"; "byte"; tag_libstubs lib]
- (S[A"-dllib"; A("-l"^(nm_libstubs lib)); A"-cclib";
- A("-l"^(nm_libstubs lib))]);
-
- flag ["link"; "library"; "ocaml"; "native"; tag_libstubs lib]
- (S[A"-cclib"; A("-l"^(nm_libstubs lib))]);
-
- flag ["link"; "program"; "ocaml"; "byte"; tag_libstubs lib]
- (S[A"-dllib"; A("dll"^(nm_libstubs lib))]);
-
- (* When ocaml link something that use the C library, then one
- need that file to be up to date.
- *)
- dep ["link"; "ocaml"; "program"; tag_libstubs lib]
- [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
-
- dep ["compile"; "ocaml"; "program"; tag_libstubs lib]
- [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
-
- (* TODO: be more specific about what depends on headers *)
- (* Depends on .h files *)
- dep ["compile"; "c"]
- headers;
-
- (* Setup search path for lib *)
- flag ["link"; "ocaml"; "use_"^lib]
- (S[A"-I"; P(dir)]);
- )
- t.lib_c;
-
- (* Add flags *)
- List.iter
- (fun (tags, cond_specs) ->
- let spec =
- BaseEnvLight.var_choose cond_specs env
- in
- flag tags & spec)
- t.flags
- | _ ->
- ()
-
- let dispatch_default t =
- dispatch_combine
- [
- dispatch t;
- MyOCamlbuildFindlib.dispatch;
- ]
-
-end
-
-
-# 476 "myocamlbuild.ml"
-open Ocamlbuild_plugin;;
-let package_default =
- {
- MyOCamlbuildBase.lib_ocaml = [("biocaml", ["src/lib"])];
- lib_c = [("biocaml", "src/lib", [])];
- flags =
- [
- (["oasis_library_biocaml_ccopt"; "compile"],
- [(OASISExpr.EBool true, S [A "-ccopt"; A "-O3"])])
- ];
- includes =
- [
- ("src/tests", ["src/lib"]);
- ("src/lwt_tests", ["src/lib"]);
- ("src/app", ["src/lib"])
- ];
- }
- ;;
-
-let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;;
-
-# 499 "myocamlbuild.ml"
(* OASIS_STOP *)
open Ocamlbuild_plugin
View
198 src/lib/biocaml_internal_pervasives.ml
@@ -15,6 +15,8 @@ module Stream = struct
let next_exn = next
let next s = try Some (next_exn s) with Stream.Failure -> None
+ let empty () = from (const None)
+
module type Streamable = sig
type 'a streamable
val stream : 'a streamable -> 'a t
@@ -27,30 +29,25 @@ module Stream = struct
exception Expected_streams_of_equal_length
- let iteri xs ~f =
- let rec aux i =
- match next xs with
- | Some x -> f i x ; aux (i + 1)
- | None -> ()
- in
- aux 0
+ let rec iteri xs ~f =
+ match peek xs with
+ | Some x -> f (count xs) x ; junk xs ; iteri xs ~f
+ | None -> ()
let iter xs ~f = iteri xs ~f:(const f)
- let iter2i_exn a b ~f =
- let rec aux i =
- match peek a, peek b with
- | Some x, Some y -> (
- junk a; junk b;
- f i x y;
- aux (i + 1)
- )
- | None, None -> ()
- | _, _ -> raise Expected_streams_of_equal_length
- in
- aux 0
+ let rec iter2i_exn xs ys ~f =
+ match peek xs, peek ys with
+ | Some x, Some y -> (
+ f (count xs) (count ys) x y;
+ junk xs ;
+ junk ys ;
+ iter2i_exn xs ys ~f
+ )
+ | None, None -> ()
+ | _, _ -> raise Expected_streams_of_equal_length
- let iter2_exn xs ys ~f = iter2i_exn xs ys ~f:(const f)
+ let iter2_exn xs ys ~f = iter2i_exn xs ys ~f:(const (const f))
let iter2i a b ~f =
try iter2i_exn a b ~f
@@ -60,25 +57,37 @@ module Stream = struct
try iter2_exn a b ~f
with Expected_streams_of_equal_length -> ()
- let rec exists xs ~f =
- match peek xs with
- | Some x when f x -> true
- | Some _ -> junk xs ; exists xs ~f
- | None -> false
+ let rec find_map xs ~f =
+ match next xs with
+ | Some x -> (
+ match f x with
+ | Some x as y -> y
+ | None -> find_map xs ~f
+ )
+ | None -> None
+
+ let find xs ~f = find_map xs ~f:(fun x -> if f x then Some x else None)
+
+ let find_exn xs ~f = match find xs ~f with
+ | Some x -> x
+ | None -> raise Not_found
+
+ let exists xs ~f = match find xs ~f with
+ | Some _ -> true
+ | None -> false
let rec for_all xs ~f =
- match peek xs with
+ match next xs with
| Some x when not (f x) -> false
- | Some _ -> junk xs ; for_all xs ~f
+ | Some _ -> for_all xs ~f
| None -> true
- let foldi xs ~init ~f =
- let rec aux i accu =
- match next xs with
- | None -> init
- | Some x -> aux (i + 1) (f i accu x)
- in
- aux 0 init
+ let rec foldi xs ~init ~f =
+ match next xs with
+ | None -> init
+ | Some x -> foldi xs ~init:(f (count xs - 1) init x) ~f
+ (* [count xs - 1] because of the call to [next], which increased the
+ stream count by one *)
let fold xs ~init ~f = foldi xs ~init ~f:(const f)
@@ -90,32 +99,25 @@ module Stream = struct
let sum = reduce ~f:( + )
let fsum = reduce ~f:( +. )
- let fold2i_exn xs ys ~init ~f =
- let rec aux i accu =
- match peek xs, peek ys with
- | Some x, Some y ->
- junk xs ;
- junk ys ;
- aux (i + 1) (f i accu x y)
- | None, None -> accu
- | _ -> raise Expected_streams_of_equal_length
- in
- aux 0 init
-
- let fold2_exn xs ys ~init ~f = fold2i_exn xs ys ~init ~f:(const f)
-
- let fold2i xs ys ~init ~f =
- let rec aux i accu =
- match peek xs, peek ys with
- | Some x, Some y ->
- junk xs ;
- junk ys ;
- aux (i + 1) (f i accu x y)
- | _ -> accu
- in
- aux 0 init
+ let rec fold2i_exn xs ys ~init ~f =
+ match next xs, next ys with
+ | Some x, Some y ->
+ let init = f (count xs - 1) (count ys - 1) init x y in
+ (* decrease by one because of the calls to [next] *)
+ fold2i_exn xs ys ~init ~f
+ | None, None -> init
+ | _ -> raise Expected_streams_of_equal_length
+
+ let fold2_exn xs ys ~init ~f = fold2i_exn xs ys ~init ~f:(const (const f))
+
+ let rec fold2i xs ys ~init ~f =
+ match next xs, next ys with
+ | Some x, Some y ->
+ let init = f (count xs - 1) (count ys - 1) init x y in
+ fold2i xs ys ~init ~f
+ | _ -> init
- let fold2 xs ys ~init ~f = fold2i xs ys ~init ~f:(const f)
+ let fold2 xs ys ~init ~f = fold2i xs ys ~init ~f:(const (const f))
let scanl xs ~init ~f =
let current = ref init in
@@ -136,15 +138,25 @@ module Stream = struct
| Some init -> scanl xs ~init ~f
| None -> invalid_arg "Biocaml_stream.scan: input stream should contain at least one value"
- let find = assert false
- let find_exn = assert false
- let find_map = assert false
- let take = assert false
- let take_while = assert false
- let take_whilei = assert false
- let skip = assert false
- let skip_while = assert false
- let skip_whilei = assert false
+ let take_whilei xs ~f =
+ let aux i =
+ match peek xs with
+ | Some x when f i x -> junk xs ; Some x
+ | _ -> None
+ in
+ from aux
+
+ let take_while xs ~f = take_whilei xs ~f:(const f)
+ let take k = take_whilei ~f:(fun j _ -> j < k)
+
+ let rec skip_whilei xs ~f =
+ match peek xs with
+ | Some x when f (count xs) x -> junk xs ; skip_whilei xs ~f
+ | _ -> from (fun _ -> next xs)
+
+ let skip_while xs ~f = skip_whilei xs ~f:(const f)
+
+ let skip n xs = assert false
let drop = assert false
let span = assert false
let group = assert false
@@ -159,7 +171,6 @@ module Stream = struct
let uniq = assert false
let range = assert false
- let empty = assert false
let init = assert false
let singleton = assert false
let loop = assert false
@@ -171,38 +182,25 @@ module Stream = struct
match peek cstr with
| None -> None
| Some _ ->
- let ans = Buffer.create 100 in
- let rec loop () =
- try
- let c = next_exn cstr in
- if c <> '\n' then (Buffer.add_char ans c; loop())
- with Failure -> ()
- in
- loop();
- Some (Buffer.contents ans)
+ let ans = Buffer.create 100 in
+ let rec loop () =
+ try
+ let c = next_exn cstr in
+ if c <> '\n' then (Buffer.add_char ans c; loop())
+ with Failure -> ()
+ in
+ loop();
+ Some (Buffer.contents ans)
in
from f
- let keep_whilei pred s =
- let f _ =
- match peek s with
- | None -> None
- | Some a ->
- if pred (count s) a
- then (junk s; Some a)
- else None
- in from f
-
- let keep_while pred = keep_whilei (fun _ a -> pred a)
- let truncate k = keep_whilei (fun j _ -> j < k)
-
let rec drop_whilei xs ~f =
match peek xs with
| None -> ()
| Some a ->
- if f (count xs) a
- then (junk xs; drop_whilei xs ~f)
- else ()
+ if f (count xs) a
+ then (junk xs; drop_whilei xs ~f)
+ else ()
let drop_while xs ~f = drop_whilei xs ~f:(fun _ a -> f a)
@@ -245,10 +243,10 @@ module Stream = struct
let result_to_exn s ~error_to_exn =
from (fun _ ->
match next s with
- | None -> None
- | Some result -> match result with
- | Ok x -> Some x
- | Result.Error x -> raise (error_to_exn x)
+ | None -> None
+ | Some result -> match result with
+ | Ok x -> Some x
+ | Result.Error x -> raise (error_to_exn x)
)
module Infix = struct
@@ -266,7 +264,7 @@ module Stream = struct
let ( --- ) x y =
if x <= y then x -- y
else loop x (fun _ prev -> if prev <= y then Some (prev - 1) else None)
-
+
let ( /@ ) x f = map x ~f
let ( // ) x f = filter x ~f
let ( //@ ) x f = filter_map x ~f
@@ -343,7 +341,7 @@ module With_result = struct
| E e -> Error e
end in
M.the_fun ()
-
+
let output_result r = `output r
let output_ok o = `output (Ok o)
let output_error e = `output (Error e)
View
26 src/lib/biocaml_internal_pervasives.mli
@@ -3,6 +3,10 @@
(**
See
{{:https://bitbucket.org/yminsky/ocaml-core/src/8808e3a2571f/base/core/lib/std.ml}std.ml}.
+
+ Semantics: (1) functions that return a stream return a "fresh"
+ stream, meaning that their count is set to 0. (2) indexed variants
+ of HOF use the internal count of the stream
*)
include module type of Core.Std
@@ -91,11 +95,11 @@ module Stream : sig
containing the successive values of the factorial function.*)
val iteri : 'a t -> f:(int -> 'a -> unit) -> unit
- val iter2i_exn : 'a t -> 'b t -> f:(int -> 'a -> 'b -> unit) -> unit
- val iter2i : 'a t -> 'b t -> f:(int -> 'a -> 'b -> unit) -> unit
+ val iter2i_exn : 'a t -> 'b t -> f:(int -> int -> 'a -> 'b -> unit) -> unit
+ val iter2i : 'a t -> 'b t -> f:(int -> int -> 'a -> 'b -> unit) -> unit
val foldi : 'a t -> init:'b -> f:(int -> 'b -> 'a -> 'b) -> 'b
- val fold2i_exn : 'a t -> 'b t -> init:'c -> f:(int -> 'c -> 'a -> 'b -> 'c) -> 'c
- val fold2i : 'a t -> 'b t -> init:'c -> f:(int -> 'c -> 'a -> 'b -> 'c) -> 'c
+ val fold2i_exn : 'a t -> 'b t -> init:'c -> f:(int -> int -> 'c -> 'a -> 'b -> 'c) -> 'c
+ val fold2i : 'a t -> 'b t -> init:'c -> f:(int -> int -> 'c -> 'a -> 'b -> 'c) -> 'c
val find : 'a t -> f:('a -> bool) -> 'a option
(** [find e ~f] returns either [Some x] where [x] is the first
@@ -110,7 +114,7 @@ module Stream : sig
val find_exn : 'a t -> f:('a -> bool) -> 'a
- val find_map : 'a t -> f:('a -> 'b option) -> 'b t
+ val find_map : 'a t -> f:('a -> 'b option) -> 'b option
val next: 'a t -> 'a option
val next_exn: 'a t -> 'a
@@ -121,14 +125,17 @@ module Stream : sig
val take_while : 'a t -> f:('a -> bool) -> 'a t
val take_whilei : 'a t -> f:(int -> 'a -> bool) -> 'a t
- val skip : int -> 'a t -> 'a t
- val skip_while : 'a t -> f:('a -> bool) -> 'a t
- val skip_whilei : 'a t -> f:(int -> 'a -> bool) -> 'a t
-
val drop : int -> 'a t -> unit
val drop_while : 'a t -> f:('a -> bool) -> unit
val drop_whilei : 'a t -> f:(int -> 'a -> bool) -> unit
+ (** Similar to [drop] but returns a fresh stream obtained after
+ discarding the [n] first elements. Being a fresh stream, the
+ count of the returned stream starts from 0 *)
+ val skip : int -> 'a t -> 'a t
+ val skip_while : 'a t -> f:('a -> bool) -> 'a t
+ val skip_whilei : 'a t -> f:(int -> 'a -> bool) -> 'a t
+
val span : 'a t -> f:('a -> bool) -> 'a t * 'a t
(** [span test e] produces two streams [(hd, tl)], such that
[hd] is the same as [take_while test e] and [tl] is the same
@@ -191,6 +198,7 @@ module Stream : sig
stream. Resulting stream raises exception at first error
seen. *)
+ val empty : unit -> 'a t
val init : int -> f:(int -> 'a) -> 'a t
val singleton : 'a -> 'a t
val loop : 'a -> f:(int -> 'a -> 'a option) -> 'a t

0 comments on commit e6d6fc1

Please sign in to comment.