From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.5 required=5.0 tests=AWL,NO_REAL_NAME,SPF_FAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id B080ABC0A for ; Tue, 19 Dec 2006 07:15:30 +0100 (CET) Received: from selenite.metnet.navy.mil (selenite.metnet.navy.mil [192.16.167.32]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id kBJ6FS6Q018365 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Tue, 19 Dec 2006 07:15:30 +0100 Received: (qmail 24330 invoked by uid 107); 19 Dec 2006 06:15:25 -0000 Received: from unknown (HELO Adric.metnet.fnmoc.navy.mil) (10.100.105.102) by selenite.metnet.navy.mil with SMTP; 19 Dec 2006 06:15:25 -0000 Received: by Adric.metnet.fnmoc.navy.mil (Postfix, from userid 760) id 38710AB40; Mon, 18 Dec 2006 22:15:01 -0800 (PST) To: jtbryant@valdosta.edu, caml-list@inria.fr Subject: Re: A Few Questions Reply-To: oleg@pobox.com Errors-To: oleg@okmij.org From: oleg@pobox.com Message-Id: <20061219061501.38710AB40@Adric.metnet.fnmoc.navy.mil> Date: Mon, 18 Dec 2006 22:15:01 -0800 (PST) X-Miltered: at discorde with ID 45878380.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; oleg:01 sig:01 functor:01 sig:01 functor:01 struct:01 foo:01 val:01 struct:01 foo:01 ocaml:01 higher-order:01 functors:01 functors:01 val:01 Jonathan T Bryant wrote: > module type AModule = sig type t end > module type BModule = > functor (A : AModule) -> > sig > type t > type s = A.t > end > module S : sig type t end > module Make = functor (B : BModule) -> S with type t = B.t and indeed the last line is problematic: S is a module (aka structure) rather than a module type (aka signature). The `with type' applies only to signatures. You have omitted S's body. In full, one would write module S : sig type t end = struct type t = unit end What is the meaning of `S with type t = B.t' then? The type `t' in S signature is already associated with unit; we can't replace it with another type B.t. Imagine if we could write module Foo : sig type t val v : t end = struct type t = unit let v = () end let module Bar = Foo with type t = int what is the value of Bar.v then? Incidentally, OCaml does support higher-order functors (that is, functors can be both arguments and results of other functors). Also, module signatures (`module type') may be components of structures. > why isn't this allowed: > val make : ('a -> 'b) -> ('a -> 'c) -> > sig type t val x : 'a -> 'b val y : 'a -> 'c end > let make a b = struct > type t = int > let x = a > let y = b > end > module X = make (fun x -> x) (fun y -> y) Hmm, the following module Make(X: sig val a : 'a -> 'a val b : 'a -> 'a end) : sig type t val x : 'a -> 'a val y : 'a -> 'a end = struct type t = int let x = X.a let y = X.b end;; module X = Make(struct let a = fun x -> x let b = fun y -> y end);; seems quite isomorphic to the desideratum, and is accepted by Ocaml. I assumed that the signature val make : ('a -> 'b) -> ('a -> 'c) has a typo: there are few interesting functions that have the type of 'a -> 'b (e.g., let rec loop x = loop x and failwith and Obj.magic). Certainly fun x -> x is not one of them. So, make (fun x -> x) (fun y -> y) in your code must raise the type error at least for that reason. > 4) I've found that in sending functions across sockets, > I can only send them between copies of the exact same binary image. > Is it possible to marshal functions to different binaries of the same > code, i.e., different platforms? Again, does native vs. bytecode make > a difference? Different platforms may have different word sizes, different alignment. Different version of the bytecode programs may be compiled by ocamlc that has different sets of primitive operations and pervasives. Your program may contain let foo () = Unix.fork () now, we serialize the closure 'foo', ship it over to a network pipe to a windows machine, deserialize and attempt to execute. What the result would be? It is far easier for the programmer to defunctionalize the part of his code that is intended to be mobile. > 5) Number-parameterized vectors Matthias Blume has done exactly that, for SML. His technique is applicable to OCaml. Although the functions like concatenation of vectors is not expressible as this requires the type system to do decimal arithmetics. It is possible in Haskell btw, with the typechecker indeed doing decimal arithmetics. Matthias Blume: No-Longer-Foreign: Teaching an ML compiler to speak C ``natively.'' In BABEL'01: First workshop on multi-language infrastructure and interoperability, September 2001, Firenze, Italy. http://people.cs.uchicago.edu/~blume/pub.html However, we can achieve essentially the same with the simpler means http://pobox.com/~oleg/ftp/ML/eliminating-array-bound-check-literally.ml Actually, we can achieve something more powerful: elimination of array bound check even if the array is allocated dynamically and its size is not known till the run-time: see especially the comment by Alain Frisch at the end of the above file.