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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 1BF937EC76 for ; Tue, 12 May 2015 23:47:21 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of pjfrey@sympatico.ca) identity=pra; client-ip=65.55.116.42; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="pjfrey@sympatico.ca"; x-sender="pjfrey@sympatico.ca"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of pjfrey@sympatico.ca designates 65.55.116.42 as permitted sender) identity=mailfrom; client-ip=65.55.116.42; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="pjfrey@sympatico.ca"; x-sender="pjfrey@sympatico.ca"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@BLU004-OMC1S31.hotmail.com) identity=helo; client-ip=65.55.116.42; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="pjfrey@sympatico.ca"; x-sender="postmaster@BLU004-OMC1S31.hotmail.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0APAwC8c1JVlSp0N0FchAuzYwEGmx88EAEBAQEBAQERAQEBAQcNCQkfMIQ5FRGBfw0DBQEBHogKpmWEBAGfboYWhSOII4EWBYtth3ugPoIpH4FugxkBAQE X-IPAS-Result: A0APAwC8c1JVlSp0N0FchAuzYwEGmx88EAEBAQEBAQERAQEBAQcNCQkfMIQ5FRGBfw0DBQEBHogKpmWEBAGfboYWhSOII4EWBYtth3ugPoIpH4FugxkBAQE X-IronPort-AV: E=Sophos;i="5.13,417,1427752800"; d="scan'208";a="118027902" Received: from blu004-omc1s31.hotmail.com ([65.55.116.42]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 12 May 2015 23:47:19 +0200 Received: from BLU436-SMTP31 ([65.55.116.9]) by BLU004-OMC1S31.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.22751); Tue, 12 May 2015 14:47:18 -0700 X-TMN: [HSJurMHqE2HRDdXi5hmcxPS5phg1S5K/] X-Originating-Email: [pjfrey@sympatico.ca] Message-ID: Date: Tue, 12 May 2015 17:47:12 -0400 From: peterfrey User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: "caml-list@inria.fr" Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 12 May 2015 21:47:17.0211 (UTC) FILETIME=[370F52B0:01D08CFD] Subject: [Caml-list] Repacking modules gives unexpected results (* I am running into a very strange problem with re-packed modules: re-packed instances of variables take on their new values, but internal functions that depend on those values are still tied to the initial values. module Make is initialized to buf = "foo" and len = (Bytes.length buf) re_pack substitutes buf = "aBar" and len = 4 gives the result: E.show():len:3 buf:foo E.buf:foo E.len:3 E.show():len:3 buf:foo E.buf:aBar E.len:4 i.e.: the data reported by show() is not changed. E.buf and E.len reflect the results of re_pack The second line above SHOULD be as follows: E.show():len:4 buf:aBar E.buf:aBar E.len:4 In fact it is, IFF the line let show() = sprintf"len:%i\tbuf:%s" len buf is also included int the repacking. Perhaps I am trying to do something that is not supported. *) open Printf module type ELT = sig val buf : bytes val len : int val show : unit -> string end module Make ( Data: sig val initial : string end) : ELT = struct let buf = Data.initial let len = (Bytes.length Data.initial) let show() = sprintf"len:%i\tbuf:%s" len buf end module Reg = struct let show (module E:ELT) = sprintf"E.show():%s\tE.buf:%s\tE.len:%i\n" (E.show()) E.buf E.len let re_pack env = (module struct include (val env:ELT) let buf = "aBar" let len = 4 (* let show() = sprintf"len:%i\tbuf:%s" len buf *) (* with this it will 'work' ... *) end : ELT ) end let byte_source_of_string initial = (module struct include Make(struct let initial = initial end) end : ELT ) ;; open Reg;; let s = byte_source_of_string "foo";; print_endline (show s);; let s' = re_pack s;; print_endline (show s');; (* show s' prints 0 - 2 demonstrating that ofs=2 and E.show() = 0 *) Peter Frey