Giter VIP home page Giter VIP logo

c-cube / ocaml-containers Goto Github PK

View Code? Open in Web Editor NEW
480.0 17.0 85.0 21.63 MB

A lightweight, modular standard library extension, string library, and interfaces to various libraries (unix, threads, etc.) BSD license.

Home Page: https://c-cube.github.io/ocaml-containers/

License: BSD 2-Clause "Simplified" License

Makefile 0.07% OCaml 99.58% Standard ML 0.09% Shell 0.26%
ocaml stdlib data-structure portable permissive-license modular lightweight

ocaml-containers's Issues

print function in Hashtbl.Make

the print combinator function contains this line (164):

Format.pp_print_string fmt "@[<hov2>tbl {@,";

which for me seems to result in literal output of the control characters. it should probably be fprintf or similar?

Missing functions

I've developed a small application using containers, and found some functions that I missed:

  • CCFloat.round : float -> float – a version that returns an int would also be useful
  • CCVector.append_gen : 'a CCVector.vector -> 'a gen -> unit
  • CCList.{first, last} : 'a list -> 'a option
  • CCHashtbl.{to_gen, values_gen, keys_gen} – I guess these can't be implemented without using an intermediate list. They would still be nice to have so that I don't need to update my code when the standard library provides a more efficient way to implement them

Some cmx files are not installed

I'm seeing warning 58 in a project:

File "_none_", line 1:
Warning 58: no cmx file was found in path for module CCString, and its interface was not compiled with -opaque

From a quick look at .opam/4.04.0+flambda/lib/containers/, it seems that the cmx produces by cppo sources are not installed.

containers.bigarray

A sub-library that provides CCBigstring or something similar, with memory-mapping, iterators (on slices), etc.

Enable most of the flags in the Makefile

Since the Makefile is for developers — while the default _oasis setting is for the user/opam package — I think it would be useful that the configure in the Makefile uses the flags --enable-tests, --enable-bench, --enable-misc,...

containers v0.16 requires oasis

I installed containers from opam and it picked version 0.16. This version requires oasis to be installed. Oasis requires a lot of dependencies and it's hard to install in windows (MSVC port). My guess is that the static version of the build system (oasis setup) was no created before making the release.

merlin can't locate definition or signature of containers functions

if i try MerlinLocate on e.g. Containers.List.random_choose i get 'CCList.random_choose' seems to originate from 'CCList' whose ML file could not be found. it would be great if this could get me to the function definition or signature to find the doc string. as it is i always have to navigate to the containers docs on the internet to have access to documentation. this may also be a merlin shortcoming, i'm not sure!

Prepare for 1.0: big cleanup/simplification

Preparing version 1.0, with some breaking changes. The goal of this release is not to add significant new features, but to improve consistency and focus on the core features and modules (in particular, droping or reducing the scope of some of the experimental modules).

The working branch is prepare-1.0 .

NOTE: please ask if you want something changed/added to the list!

Todo list

  • more consistent labels (in particular, replace ~or_ by ~default)
  • label functions (iter', map', …) for CCList and the others?
  • doc (#85)
  • remove int_, bool_, etc. in CCOrd
  • make CCIO.File.walk work properly with symlinks, even broken
    • deal with errors and files that do not actually exist
    • [ ] add CCIO.File.is_symlink
    • [ ] add CCIO.File.deref : ?recursive:bool -> string -> string
    • [ ] make CCIO.File.walk_item = [Dir | File | Symlink] (breaking compat)
  • much simpler S-expression library using Lexing (see nunchaku)
  • rewrite bitfield (much simpler version, almost functor-free, Bit_set)
  • improve CCFormat (see #82)
    • CCFormat.of_to_string : ('a -> string) -> 'a t
    • CCFormat.const : 'a t -> 'a -> unit t (to hide the type 'a)
    • CCFormat.text to mimick Format.pp_print_text
    • CCFormat.return : (unit,…) format4 -> unit (for strings without arguments)
    • CCFormat.some : 'a t -> 'a option t (prints nothing if None, same as arg if Some x)
    • remove start/stop arguments?
    • make sep a argument-free formatter, default ",@ ", using Format.fprint out "%(%)" sep
      to print it in combinators
      OR use unit t with return: arg-free formatter -> unit t and sp = return ",@ " or sth
  • add CCOrd.Infix
  • remove CCPrint (just use format)
    • use pp as pretty-printer everywhere, and remove Buffer.t printers
  • remove containers.advanced (refer to olinq)
  • remove bigarray library:
    • remove Array1 (point to oml or similar instead)
    • remove CCBigstring (point to bigstring library instead)
  • improve CCUnix
    • adding simple functions such as popen (already with_process_*)
    • functions returning lists of lines?
  • remove threads library and make it into its own repo/package (if anyone uses it — need more tests)
  • CCList:
    • flatten CCList.Set
    • flatten CCList.Idx
    • [ ] flatten CCList.Assoc
    • move CCList.Zipper into its own module (in containers.data)
    • what about CCList.Ref? can keep it, probably
  • move CCArray.Sub into its own module (in containers.data), add many tests
  • [ ] move CCString.Sub into its own module (in containers.data)
  • remove containers.string, merging useful functionality into CCString
    • add edit_distance to CCString, from CCLevenshtein
    • [ ] add submodule Edit_distance_automaton (with compiled automaton + index, maybe)
    • just remove CCKMP, make CCString.Find public (provides same functionality)
    • remove App_parse
    • move CCParse into core
    • use parser combinators from oasis-parser for CCParse (string input only!) + update tests
  • use result everwhere, drop the polymorphic variants that remain
  • remove CCError in favor of CCResult
  • use Hashtbl.seeded_hash for implementing better hash combinators in CCHash (from smbc)
  • improve CCGraph (functor designed for local def?)

before pre-release:

  • [ ] remove all @since annotations
  • remove deprecated functions
  • apply ocp-indent

improve `CCFormat`

  • make start and stop empty by default in all printers (in 4ff174c)
  • add Dump sub-module with OCaml-like printing (in 0d9d17d)
  • something to change/enable/disable colors dynamically (in 9045fcc)
  • string-producing version of with_color{,f} (in 9045fcc)

Provide a module CCPervasives

This module would shadow the standard List, etc modules.

Would be great to also have a findlib library that adds "-open CCPervasives" to ocamlc invocations.

Char.print ?

i stumbled upon the fact that there is no Char module and therefore also no Char.print (analogous to Int.print etc) might this be a worthwhile addition?

introducing fold_until convenience function

Option 1:

let rec fold_until (f: 'b -> 'a -> 'b * bool) (acc:'b) = 
  function | [] -> acc | e::l -> let acc, cont = f acc e in if not cont then acc else 
   fold_until f acc l;;
val fold_until : ('b -> 'a -> 'b * bool) -> 'b -> 'a list -> 'b = <fun>                                                                             

Pros: can accumulate and terminate on last step.
Cons: more complicated return value of the accumulator function

Option 2:

 let rec fold_until (f: 'b -> 'a -> 'b option) (acc:'b) = 
   function | [] -> acc  
   | e::l -> match f acc e with None -> acc | Some acc -> fold_until f acc l;;
val fold_until : ('b -> 'a -> 'b option) -> 'b -> 'a list -> 'b = <fun>                                                                             

Pros: simple accumulator with use of options
Cons: can't accumulate on last step

In either case, I would like to add this function to CCList, CCArray, Gen, and where-ever else it makes sense. So, do you think this function merits an addition to the library? And which signature do you prefer?

monadic input for CCSexp

experiment with parametrizing the parser of CCSexp with something like:

module type INPUT = sig
  type 'a m  (* IO monad *)
  type t  (* input *)

  val return : 'a -> 'a m
  val (>>=) : 'a m -> ('a -> 'b m) -> 'b m

  val input : t -> Bytes.t -> int -> int -> int m
  (* input into this bytes buffer *)
end

This can be used with Lwt or with a blocking monad (type 'a m = 'a). Also, allows to read quite easily from bigarrays, channels, strings, etc.

bind in CCOpt

is there a reason that bind is only present in infix form in CCOpt? i'm asking since i just came across a situation where the normal bind with signature (a -> b t) -> a t -> b t would have been handy because of the argument order.

feature request: analog of argsort in numpy

i was looking for a function ('a -> 'a -> int) -> 'a array -> int array that gives the indices that successive array elements would have in a sorted array (sorted by the compare function given first). i.e. the ranking of the elements. something like that is useful for all kinds of rank statistics.

CCError generic printer

CCError.pp and CCError.print only accept a printer argument for the 'good type, not for 'bad:

val pp : 'a printer -> ('a, string) t printer
val print : 'a formatter -> ('a, string) t formatter

I'm using non-string types for errors, so a pp method that takes two printers (like CCMap.S.pp) would be useful.

Can't install 0.22

(sequence is installed with 0.9)

> opam install containers
The following actions will be performed:
  ∗  install containers 0.22

=-=- Gathering sources =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  🐫 
[containers] Archive in cache

=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  🐫 
[ERROR] The compilation of containers failed at "make build".
Processing  1/1: [containers: ocamlfind remove]
#=== ERROR while installing containers.0.22 ===================================#
# opam-version 1.2.2
# os           darwin
# command      make build
# path         /Users/dbuenzli/.opam/4.03.0/build/containers.0.22
# compiler     4.03.0
# exit-code    2
# env-file     /Users/dbuenzli/.opam/4.03.0/build/containers.0.22/containers-92685-d2c37b.env
# stdout-file  /Users/dbuenzli/.opam/4.03.0/build/containers.0.22/containers-92685-d2c37b.out
# stderr-file  /Users/dbuenzli/.opam/4.03.0/build/containers.0.22/containers-92685-d2c37b.err
### stdout ###
# [...]
# /Users/dbuenzli/.opam/4.03.0/bin/ocamlfind ocamldep -package bytes -package sequence -package result -modules src/advanced/CCCat.ml > src/advanced/CCCat.ml.depends
# cppo -D 'OCAML_MAJOR 4' -D 'OCAML_MINOR 3' -o src/advanced/CCMonadIO.ml src/advanced/CCMonadIO.cppo.ml
# /Users/dbuenzli/.opam/4.03.0/bin/ocamlfind ocamldep -package bytes -package sequence -package result -modules src/advanced/CCMonadIO.ml > src/advanced/CCMonadIO.ml.depends
# /Users/dbuenzli/.opam/4.03.0/bin/ocamlfind ocamlc -c -g -annot -bin-annot -safe-string -short-paths -no-alias-deps -w A -I src/core -w -4 -w -44 -package bytes -package sequence -package result -I src/advanced -I src/core -o src/advanced/containers_advanced.cmo src/advanced/containers_advanced.ml
# /Users/dbuenzli/.opam/4.03.0/bin/ocamlfind ocamlc -c -g -annot -bin-annot -safe-string -short-paths -no-alias-deps -w A -I src/core -w -4 -w -44 -package bytes -package sequence -package result -I src/advanced -I src/core -o src/advanced/CCLinq.cmo src/advanced/CCLinq.ml
# + /Users/dbuenzli/.opam/4.03.0/bin/ocamlfind ocamlc -c -g -annot -bin-annot -safe-string -short-paths -no-alias-deps -w A -I src/core -w -4 -w -44 -package bytes -package sequence -package result -I src/advanced -I src/core -o src/advanced/CCLinq.cmo src/advanced/CCLinq.ml
# File "src/advanced/CCLinq.ml", line 215, characters 14-30:
# Error: Unbound value Sequence.flatMap
# Hint: Did you mean flat_map?
# Command exited with code 2.
### stderr ###
# E: Failure("Command ''/Users/dbuenzli/.opam/4.03.0/bin/ocamlbuild' src/core/containers.cma src/core/containers.cmxa src/core/containers.a src/core/containers.cmxs src/io/containers_io.cma src/io/containers_io.cmxa src/io/containers_io.a src/io/containers_io.cmxs src/unix/containers_unix.cma src/unix/containers_unix.cmxa src/unix/containers_unix.a src/unix/containers_unix.cmxs src/sexp/containers_sexp.cma src/sexp/containers_sexp.cmxa src/sexp/containers_sexp.a src/sexp/containers_sexp.cmxs src/data/containers_data.cma src/data/containers_data.cmxa src/data/containers_data.a src/data/containers_data.cmxs src/iter/containers_iter.cma src/iter/containers_iter.cmxa src/iter/containers_iter.a src/iter/containers_iter.cmxs src/string/containers_string.cma src/string/containers_string.cmxa src/string/containers_string.a src/string/containers_string.cmxs src/advanced/containers_advanced.cma src/advanced/containers_advanced.cmxa src/advanced/containers_advanced.a src/advanced/containers_advanced.cmxs src/bigarray/containers_bigarray.cma src/bigarray/containers_bigarray.cmxa src/bigarray/containers_bigarray.a src/bigarray/containers_bigarray.cmxs src/threads/containers_thread.cma src/threads/containers_thread.cmxa src/threads/containers_thread.a src/threads/containers_thread.cmxs src/top/containers_top.cma src/top/containers_top.cmxa src/top/containers_top.a src/top/containers_top.cmxs examples/id_sexp.native -use-ocamlfind -j 1 -tag debug' terminated with error code 10")
# make: *** [build] Error 1



=-=- Error report -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  🐫 
The following actions failed
  ∗  install containers 0.22
No changes have been performed

=-=- containers.0.22 troubleshooting =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  🐫 
=> Small release of containers, making use of the new releases of
     qtest and qcheck.

monad-building functor

In containers.advanced, a functor

module MakeMonad(M : sig
  type 'a t
  val return : 'a -> 'a t 
  val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
  val map : [`Redefine | `Use of ('a t -> ('a -> 'b) -> 'b t)]
  (* etc. for other optional values *)
end) : sig
  (* copy monad stuff *)
  (* add applicative stuff *)
  (* add some sequence operators? *)
end

CCChar.{of,to}_int

The following functions would be useful:

  • CCChar.of_int : int -> char option
  • CCChar.of_int_exn : int -> char
  • CCChar.to_int : char -> int

file naming bug?

i just tried to use CCInt and got this:

Error: Wrong file naming: $HOME/.opam/4.02.3/lib/containers/cCint.cmi
contains the compiled interface for 
CCint when CCInt was expected
Command exited with code 2.

lwt functional streams

module Stream : sig
  type 'a t = [`Nil | `Cons of 'a * 'a t] Lwt.t

  val push : 'a t -> 'a -> unit Lwt.t
  val next : 'a t -> ('a * 'a t) option
  val iter_s : ('a -> unit Lwt.t) -> 'a t -> unit Lwt.t

  (* etc. *)
end

should make it easier to work with streams.

extract conv.ml

I'm interested in using conv.ml in one of my project, but I don't want to depend on Unix. By any chance, do you plan to make a stand-alone library for conv ?

Missing infix operators for half-open ranges

The new CCList.Infix.(--) is nice, but it would be even nicer to have an alternative operator more suitable for dealing in algorithms with dynamic input, where half-open ranges are often seen. I suggest using --< which communicates nicely the fact that the right end of the range is open, ie. 1 --< 3 = [1; 2].

The empty range would be produced if the left and right bounds are the same. 1 --< 1 = [].

--< should also not automatically choose to make a descending range, but instead require that the second argument is never less than the first argument. The Invalid_argument in this situations seems appropriate to me, if Containers doesn't make use of something else.

If the user desires to write a descending range, he may choose to use the non-infix functions for that, or possibly List.rev. In practice I find descending ranges be much more rare than ascending ones, and in particular there are basically zero cases where the same piece of code would deal with ranges going either way, depending on arguments. So it's best to signal about those cases, as they are likely indicative of an error.

The --< operator should be provided in all the modules that currently provide --.

0.6.1 fails to build with OPAMBUILDDOC=1

Solver failed:
  Ocamlbuild knows of no rules that apply to a target named containers_lwt.odocl. This can happen if you ask Ocamlbuild to build a target with the wrong extension (e.g. .opt instead of .native) or if the source files live in directories that have not been specified as include directories.
Backtrace:
  - Failed to build the target containers_lwt.docdir/index.html
      - Building containers_lwt.docdir/index.html:
          - Failed to build all of these:
              - Building containers_lwt.odocl
              - Building containers_lwt.odocl
Makefile:10: recipe for target 'doc' failed

Clarify the use of sub libraries in the tutorial

The tutorial makes it clear how to get up and running with the core library by providing sample code. However, the "To go further" section is not detailed enough for a beginner how to get code compiling and linking using containers.data.

Core style prefix/suffix functions

These are best explained through type signatures:

val chop_suffix : t -> suffix:t -> t option

val chop_prefix : t -> prefix:t -> t option

These are very useful and I often myself reaching them for them. Would be great if containers had them as well. Obviously the labels/names will need to be adjusted.

Apologies if containers already has them. I'm still learning the ropes.

0.7 failed compile in OPAM on OS X

I had containers 0.4.1 installed. It worked great. I did opam update. I did opam upgrade. containers was just plain gone. I did opam install containers. I got a long error.

#=== ERROR while installing containers.0.7 ====================================#
# opam-version 1.2.0
# os           darwin
# command      make build
# path         /Users/mcc/.opam/4.02.1/build/containers.0.7
# compiler     4.02.1
# exit-code    2
# env-file     /Users/mcc/.opam/4.02.1/build/containers.0.7/containers-96695-5f1023.env
# stdout-file  /Users/mcc/.opam/4.02.1/build/containers.0.7/containers-96695-5f1023.out
# stderr-file  /Users/mcc/.opam/4.02.1/build/containers.0.7/containers-96695-5f1023.err
### stdout ###
# ...[truncated]
# /Users/mcc/.opam/4.02.1/bin/ocamlfind ocamlopt -c -g -annot -bin-annot -no-alias-deps -w A -w -4 -w -44 -for-pack Containers_string -I src/string -o src/string/KMP.cmx src/string/KMP.ml
# /Users/mcc/.opam/4.02.1/bin/ocamlfind ocamlopt -c -g -annot -bin-annot -no-alias-deps -w A -w -4 -w -44 -for-pack Containers_string -I src/string -o src/string/levenshtein.cmx src/string/levenshtein.ml
# touch src/string/containers_string.mli  ; if  /Users/mcc/.opam/4.02.1/bin/ocamlfind ocamlopt -pack -g -annot -bin-annot -I src/string src/string/KMP.cmx src/string/levenshtein.cmx -o src/string/containers_string.cmx  ; then  rm -f src/string/containers_string.mli  ; else  rm -f src/string/containers_string.mli  ; exit 1; fi
# /Users/mcc/.opam/4.02.1/bin/ocamlfind ocamlopt -a src/string/containers_string.cmx -o src/string/containers_string.cmxa
# + /Users/mcc/.opam/4.02.1/bin/ocamlfind ocamlopt -a src/string/containers_string.cmx -o src/string/containers_string.cmxa
# /usr/bin/ranlib: object: src/string/containers_string.a(containers_string.o) malformed object (unknown load command 4)
# ar: internal ranlib command failed
# File "_none_", line 1:
# Error: Error while creating the library src/string/containers_string.a
# Command exited with code 2.
### stderr ###
# W: Cannot find source file matching module 'containers_misc' in library containers_misc
# W: Cannot find source file matching module 'containers_string' in library containers_string
# E: Failure("Command ''/Users/mcc/.opam/4.02.1/bin/ocamlbuild' src/core/containers.cma src/core/containers.cmxa src/core/containers.a src/core/containers.cmxs src/io/containers_io.cma src/io/containers_io.cmxa src/io/containers_io.a src/io/containers_io.cmxs src/sexp/containers_sexp.cma src/sexp/containers_sexp.cmxa src/sexp/containers_sexp.a src/sexp/containers_sexp.cmxs src/data/containers_data.c...[truncated]
# make: *** [build] Error 1


=-=- containers.0.7 troubleshooting -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  🐫 
=> containers is now split into finer-grained sub-libraries, including
       `containers.io`, `containers.iter`, `containers.sexp`, `containers.data`.
       CCGen and CCSequence have been removed, consider using the libraries
       `gen` and `sequence` on opam.
Andis-Macbook:emily-ocaml mcc$ 

I mentioned this on #ocaml freenode and Whitequark mentioned:

 <whitequark> the problem is that os x is a [redacted]. their ar can't create empty archives, they know about it since, like, 2007, and they do not give a [redacted]
[snip]
 <whitequark> mcc: http://caml.inria.fr/mantis/view.php?id=6550#c12345

(Whitequark said a cuss!)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.