Re: [Caml-list] a question about ocamlopt and ocamldep
On 03/13/2012 06:34 PM, Matthias Puech wrote: This is consistent with how ocamlc/ocamlopt work: separate compilation is ensured the way you think by bytecode .cmo compilation: to build a module, you only need the *interfaces* of its dependencies, but it is unfortunately not ensured when compiling to native code, because of the global (inter-modules) optimizations performed (inlining AFAIK). Thus, to build a .cmx module, you need to be aware of the actual *code* of its dependencies. :-( -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] a question about ocamlopt and ocamldep
:-( I don't understand. Why is it sad to have the *ability* to perform cross-module implementation-dependent optimizations (at the inevitable cost of locally damaging separate compilation) *if* you wish? On Wed, Mar 14, 2012 at 11:31 AM, Matej Košík 5764c029b688c1c0d24a2e97cd7...@gmail.com wrote: On 03/13/2012 06:34 PM, Matthias Puech wrote: This is consistent with how ocamlc/ocamlopt work: separate compilation is ensured the way you think by bytecode .cmo compilation: to build a module, you only need the *interfaces* of its dependencies, but it is unfortunately not ensured when compiling to native code, because of the global (inter-modules) optimizations performed (inlining AFAIK). Thus, to build a .cmx module, you need to be aware of the actual *code* of its dependencies. :-( -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Very slow compilation
Yo, I don't know if this helps, but I can create arbitrary compilation times with very small code samples: let sink (a,f) = f a let base = () let finish () = () let step () = () let fold (a,f) g = g (a,f) let step0 h (a,f) = fold (h a,f) let f z = fold (base, finish) z let a z = step0 step z let () = let () = f a a a a a a a a a a a a a a a a a a a a a a a sink in ();; $ time ocamlc vararg.ml real 1m9.372s user 1m9.264s sys 0m0.044s Try adding a few a's and see what that gives. have fun, Romain. PS I'm quite clueless about what's going on exactly. I just stumbled onto this tinkering around with MLton's fold vararg solutions. -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Re: Parsing cmi file
There is the cmigrep tool found on http://homepage.mac.com/letaris/ . I have no idea about current status though; http://jun.furuse.info/hacks seems to imply it works on 3.12. On Wed, Mar 14, 2012 at 6:38 PM, ri...@happyleptic.org wrote: -[ Wed, Mar 14, 2012 at 01:30:29PM -0400, Hongbo Zhang ] Another thought, I know there is a tool of hoogle for ocaml, but it's online, is there some offline hoogle offline? Yes, ocamlbrowser (if you have support for Tk). IIRC you can search by type. -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs -- ___ Raphael -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Parsing cmi file
On Tue, Mar 13, 2012 at 05:52:37PM -0400, bob zhang wrote: Hi list, I noticed that Godi can pretty print cmi files, is there already libraries parsing cmi files? cmigrep may be worth looking at. It's also a nasty(-ish) hack since it has to use the compiler sources. I agree it would be nice to have a formal API, but I can understand why the OCaml team wouldn't want to have to maintain such a thing. Rich. -- Richard Jones Red Hat -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Parsing cmi file
On 03/14/2012 07:14 PM, Hongbo Zhang wrote: I tried, it does not compile, but it would be not hard to fix, I guess. In Debian, we apply the following patches to compile it: http://patch-tracker.debian.org/package/cmigrep/1.5-9 FWIW, it compiles and runs perfectly well with any OCaml = 3.10. Regards, -- Mehdi Dogguy مهدي الدڤي http://dogguy.org/ -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
[Caml-list] Arrays and private types
hello world. In my application I'm using arrays all over, and lately I've discovered a couple of bugs related to the fact that I was using the index of one array to get the element of another array. Since both indexes are int the compiler could not help me at all. Using private types it seems I can solve this problem without loosing anything (??). This is what I came up with ... and since, I was at it I've also restricted the type of the Array... my questions are : - Is there a better way of doing it, such that the type of IntArray is not IntArray.T.t array but rather int array ? Consider that I'm going to this deal of trouble only because I want to define the Array signature (with the private annotation) only once and not for each type of array I want to instantiate ... - how can avoid this problem ? # let a = IntArray.make 10 0 ;; val a : IntArray.T.t array = [|0; 0; 0; 0; 0; 0; 0; 0; 0; 0|] # a.(1);; - : IntArray.T.t = 0 # # IntArray.get a 1 ;; Error: This expression has type int but an expression was expected of type IntArray.t Ideally I'd like the same type of error when using a.(1) ... thanks pietro --- module type T = sig type t end module MakePrivateArraySig (T : T) = struct module type Sig = sig type t = private int val of_int : int - t val to_int : t - int val length : T.t array - int val get : T.t array - t - T.t val set : T.t array - t - T.t - unit val make : int - T.t - T.t array val create : int - T.t - T.t array val init : int - (t - T.t) - T.t array val append : T.t array - T.t array - T.t array val concat : T.t array list - T.t array val to_list : T.t array - T.t list val of_list : T.t list - T.t array val iter : (T.t - unit) - T.t array - unit val map : (T.t - 'b) - T.t array - 'b array val iteri : (t - T.t - unit) - T.t array - unit val mapi : (t - T.t - 'b) - T.t array - 'b array val fold_left : (T.t - 'b - T.t) - T.t - 'b array - T.t val fold_right : (T.t - 'b - 'b) - T.t array - 'b - 'b val unsafe_get : T.t array - int - T.t val unsafe_set : T.t array - int - T.t - unit end end module type IntArrayType = sig module T : sig type t = int end include MakePrivateArraySig(T).Sig end module type FloatArrayType = sig module T : sig type t = float end include MakePrivateArraySig(T).Sig end module IntArray : IntArrayType = struct type t = int module T = struct type t = int end include Array let of_int x = x let to_int x = x end module FloatArray : FloatArrayType = struct type t = int module T = struct type t = float end include Array let of_int x = x let to_int x = x end --- This is clearly the solution for the first question, but I'll be forced to write a signature for each array ... I feel that there is a clean way of doing this ... --- module StringArray : Sig = struct type t = int include Array let of_int x = x let to_int x = x end ;; module type Sig = sig type t = private int val of_int : int - t val to_int : t - int val length : string array - int val get : string array - t - string val set : string array - t - string - unit val make : int - string - string array val create : int - string - string array val init : int - (t - string) - string array val append : string array - string array - string array val concat : string array list - string array val to_list : string array - string list val of_list : string list - string array val iter : (string - unit) - string array - unit val map : (string - 'a) - string array - 'a array val iteri : (t - string - unit) - string array - unit val mapi : (t - string - 'a) - string array - 'a array val fold_left : (string - 'a - string) - string - 'a array - string val fold_right : (string - 'a - 'a) - string array - 'a - 'a val unsafe_get : string array - int - string val unsafe_set : string array - int - string - unit end # let c = StringArray.make 10 a;; val c : string array = [|a; a; a; a; a; a; a; a; a; a|] # StringArray.set c 1 aa;; Error: This expression has type int but an expression was expected of type StringArray.t # StringArray.set c (StringArray.of_int 1) aa;; - : unit = () # c;; - : string array = [|a; aa; a; a; a; a; a; a; a; a|] # -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
[Caml-list] Tuples (covariant immutable arrays)
Hi, Does anyone have a Tuple module that exports arrays as immutable and covariant? Thanks, Łukasz -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Tuples (covariant immutable arrays)
On Wed, Mar 14, 2012 at 10:03 PM, Edgar Friendly thelema...@gmail.com wrote: Batteries has a Cap submodule that provides type-level protection for arrays so they can be Read-only/Write-only/Read-write. The same idea with a variance annotation and just read-only access seems to be what you're looking for, no? It seems no, because Cap is invariant, and for a reason: for example, Hashtbl.Cap.of_table says This operation involves no copying. In other words, in let cap = of_table a in ..., any modification in a will also have effect on cap and reciprocally. What I'm thinking about is type +'a Tuple.t with Tuple.of_list and Tuple.of_array both performing a copy. -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Tuples (covariant immutable arrays)
Ok, trivial enough a change. You'll have to make a case for the usefulness of this data structure being in batteries for us to make the change, otherwise, feel free to use the batteries code as a basis for your Tuple data structure. LGPL2.1+linking exception should be sufficiently liberal for most uses. E. btw, link to the docs I meant to include in my first email: http://ocaml-batteries-team.github.com/batteries-included/hdoc/BatArray.Cap.html On Wed, Mar 14, 2012 at 5:12 PM, Lukasz Stafiniak lukst...@gmail.comwrote: On Wed, Mar 14, 2012 at 10:03 PM, Edgar Friendly thelema...@gmail.com wrote: Batteries has a Cap submodule that provides type-level protection for arrays so they can be Read-only/Write-only/Read-write. The same idea with a variance annotation and just read-only access seems to be what you're looking for, no? It seems no, because Cap is invariant, and for a reason: for example, Hashtbl.Cap.of_table says This operation involves no copying. In other words, in let cap = of_table a in ..., any modification in a will also have effect on cap and reciprocally. What I'm thinking about is type +'a Tuple.t with Tuple.of_list and Tuple.of_array both performing a copy. -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Tuples (covariant immutable arrays)
type +'a t = (int - 'a) * int let get (a: 'a t) i = (fst a) i let length (a: 'a t) = snd a let of_array (a: 'a array) : 'a t = let a' = Array.copy a in (Array.get a', Array.length a') should be enough -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Arrays and private types
Here is a proposal: https://gitorious.org/gasche-snippets/private-array-keys-type/blobs/master/private_array_key_types.ml It works by using a functor to generate fresh private types for keys. Note that the arrays themselves are still polymorphic (no IntArray FloatArray etc.). The user still has to use the discipline to produce a new application of ArrayMake each time she wants to use a different kind of array: if she only does `module A = ArrayMake(struct end)` and then use `A` for everything, there will be no additional safety guarantee. On Wed, Mar 14, 2012 at 9:12 PM, Pietro Abate pietro.ab...@pps.jussieu.fr wrote: hello world. In my application I'm using arrays all over, and lately I've discovered a couple of bugs related to the fact that I was using the index of one array to get the element of another array. Since both indexes are int the compiler could not help me at all. Using private types it seems I can solve this problem without loosing anything (??). This is what I came up with ... and since, I was at it I've also restricted the type of the Array... my questions are : - Is there a better way of doing it, such that the type of IntArray is not IntArray.T.t array but rather int array ? Consider that I'm going to this deal of trouble only because I want to define the Array signature (with the private annotation) only once and not for each type of array I want to instantiate ... - how can avoid this problem ? # let a = IntArray.make 10 0 ;; val a : IntArray.T.t array = [|0; 0; 0; 0; 0; 0; 0; 0; 0; 0|] # a.(1);; - : IntArray.T.t = 0 # # IntArray.get a 1 ;; Error: This expression has type int but an expression was expected of type IntArray.t Ideally I'd like the same type of error when using a.(1) ... thanks pietro --- module type T = sig type t end module MakePrivateArraySig (T : T) = struct module type Sig = sig type t = private int val of_int : int - t val to_int : t - int val length : T.t array - int val get : T.t array - t - T.t val set : T.t array - t - T.t - unit val make : int - T.t - T.t array val create : int - T.t - T.t array val init : int - (t - T.t) - T.t array val append : T.t array - T.t array - T.t array val concat : T.t array list - T.t array val to_list : T.t array - T.t list val of_list : T.t list - T.t array val iter : (T.t - unit) - T.t array - unit val map : (T.t - 'b) - T.t array - 'b array val iteri : (t - T.t - unit) - T.t array - unit val mapi : (t - T.t - 'b) - T.t array - 'b array val fold_left : (T.t - 'b - T.t) - T.t - 'b array - T.t val fold_right : (T.t - 'b - 'b) - T.t array - 'b - 'b val unsafe_get : T.t array - int - T.t val unsafe_set : T.t array - int - T.t - unit end end module type IntArrayType = sig module T : sig type t = int end include MakePrivateArraySig(T).Sig end module type FloatArrayType = sig module T : sig type t = float end include MakePrivateArraySig(T).Sig end module IntArray : IntArrayType = struct type t = int module T = struct type t = int end include Array let of_int x = x let to_int x = x end module FloatArray : FloatArrayType = struct type t = int module T = struct type t = float end include Array let of_int x = x let to_int x = x end --- This is clearly the solution for the first question, but I'll be forced to write a signature for each array ... I feel that there is a clean way of doing this ... --- module StringArray : Sig = struct type t = int include Array let of_int x = x let to_int x = x end ;; module type Sig = sig type t = private int val of_int : int - t val to_int : t - int val length : string array - int val get : string array - t - string val set : string array - t - string - unit val make : int - string - string array val create : int - string - string array val init : int - (t - string) - string array val append : string array - string array - string array val concat : string array list - string array val to_list : string array - string list val of_list : string list - string array val iter : (string - unit) - string array - unit val map : (string - 'a) - string array - 'a array val iteri : (t - string - unit) - string array - unit val mapi : (t - string - 'a) - string array - 'a array val fold_left : (string - 'a - string) - string - 'a array - string val fold_right : (string - 'a - 'a) - string array - 'a - 'a val unsafe_get : string array - int - string val unsafe_set : string array - int - string - unit end # let c = StringArray.make 10 a;; val c : string array = [|a; a; a; a; a; a; a; a; a; a|] # StringArray.set c 1 aa;; Error: This expression has type int but an expression was expected of type StringArray.t # StringArray.set c (StringArray.of_int 1)