From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 996E281792 for ; Sat, 29 Jun 2013 09:32:10 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.214.42; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.214.42 as permitted sender) identity=mailfrom; client-ip=209.85.214.42; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-bk0-f42.google.com) identity=helo; client-ip=209.85.214.42; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-bk0-f42.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhoIAIOMzlHRVdYqjWdsb2JhbABagztJmnORe5IifAgWDgEBAQEHCwsJEgYkgiMBAQUnGQEbEgsBAwwGBQsNDSEiAREBBQEKEgYTCAqHagEDDwydMoxNgn+EDwoZJwMKWId0AQUMjGKCaAeDZwOTc4NSgSmKcINHFimEOTo X-IPAS-Result: AhoIAIOMzlHRVdYqjWdsb2JhbABagztJmnORe5IifAgWDgEBAQEHCwsJEgYkgiMBAQUnGQEbEgsBAwwGBQsNDSEiAREBBQEKEgYTCAqHagEDDwydMoxNgn+EDwoZJwMKWId0AQUMjGKCaAeDZwOTc4NSgSmKcINHFimEOTo X-IronPort-AV: E=Sophos;i="4.87,964,1363129200"; d="scan'208";a="23893141" Received: from mail-bk0-f42.google.com ([209.85.214.42]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 29 Jun 2013 09:32:10 +0200 Received: by mail-bk0-f42.google.com with SMTP id jk13so1047785bkc.1 for ; Sat, 29 Jun 2013 00:32:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=n2S8x4MPqrDLejf03SMbqOJwl9+Ks2B0JC15l5eY96Q=; b=bZHk8hhh6LOD6lMboZQJaRC7xiRCt+vZfQxAX3CmTH7hGxdbgu6fUPVWpBaaZ10+XB jlRwsRdNAs27OYZu0ReEziVAeK5otijnrwVjckHotoIvJbFL0D46ZHK1uxajyKGkEDzr KTl762zoSm7fGBtQLTkjFcH22J1DoTSsQ5j/f9u5uKBNSVBXfLDR0aNwVWK6I0xe9ytW hP/ONaCNmMX5FGx/jDvLYHb5UqFiMCVB0ohxrGMiq0n0Rk0WIrEwJPZ+djrlXJanIsoi KwMkw3QyU/eG9UOA74oufYfv6UK4KcZ3a89yAw9/AmilofoCewR3oEv2NS8MbFhAlFyq Ow4g== X-Received: by 10.204.79.70 with SMTP id o6mr2173019bkk.94.1372491129447; Sat, 29 Jun 2013 00:32:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.20.131 with HTTP; Sat, 29 Jun 2013 00:31:28 -0700 (PDT) In-Reply-To: <1372463499-sup-1099@nixos> References: <1372089559-sup-2177@nixos> <1372463499-sup-1099@nixos> From: Gabriel Scherer Date: Sat, 29 Jun 2013 09:31:28 +0200 Message-ID: To: Marc Weber Cc: caml-list Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Caml-list] Re: ocamlopt vs camlc, different behaviour - how to track down? The problem you hit is the so-called "Value restriction" in ML, which makes certain expressions that possibly have side-effects non-polymorphic, in order to avoid having polymorphic expressions that allocated memory location (allocating mutable memory is a particular kind of side-effects, but the over-zealous static judgment has to forbid other things as well, in particular any unknown functional call, and dubious "let..in..." constructs). You can in fact solve that problem by turning let empty = let () = print_string "[\"pMap.ml\": 81:12-42 81:42]\n" in { cmp = compare; map = Empty; }; into let empty = (print_string "[\"pMap.ml\": 81:12-42 81:42]\n"; { cmp = compare; map = Empty; }) While the two expression have the exact same dynamic semantics (they execute in the same way), with the (e1; e2) form the compiler can trivially see that no memory allocation that would have been done in e1 will be reused in the value of e2, so it's safe to generalize (e1;e2) as soon as e2 only is effect-free. In the general case (let p = e1 in e2), parts of e1 may be reused in e2, so this expression is not generalized as soon as e1 has effects. In that case (let () = e1 in e2), it would be safe to ignore e1 as no part of it is bound and reused in e2, and more generally one may do an escape analysis do refine generalization here. But as all expressions (let p = e1 in e2) where no part of e1 are reused in e2 can be rewritten into (e1; e2), it makes sense to simplify the specification of the type-checker and favor the latter form. The camlp4 code generator you use was just not aware of this subtlety. On Sat, Jun 29, 2013 at 1:54 AM, Marc Weber wrote: > Error: The implementation m.ml does not match the interface m.cmi: > Values do not match: > val empty : ('_a, 'b) t > is not included in > val empty : ('a, 'b) t > File "m.ml", line 11, characters 4-9: Actual declaration > make: *** [m.cmo] Error 2 > > > files as zip: http://mawercer.de/tmp/test-case.zip > contents: > > makefile ========================= > > default: m.cmo > > m.cmi: m.mli > ocamlc -o $@ -c $< > > m.cmo: m.ml m.cmi > ocamlc -o $@ -c $< > m.ml ============================ > > > type ('k, 'v) map = > | Empty > | Node of ('k, 'v) map * 'k * 'v * ('k, 'v) map * int > > type ('k, 'v) t = > { > cmp : 'k -> 'k -> int; > map : ('k, 'v) map; > } > > let empty = > let () = print_string "[\"pMap.ml\": 81:12-42 81:42]\n" > in { cmp = compare; map = Empty; }; > > > m.mli ============================ > > > type ('a, 'b) t > > val empty : ('a, 'b) t > > > In cases like first, find_all I was able to workaround this compilation > error by adding explicit parameters, eg > > find_all a b = find a b instead of find_all = find > > However in the "empty" case I need more help. How to make this case > compile ? > > Marc Weber > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs