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 B76487F8C9 for ; Mon, 18 Jan 2016 17:02:13 +0100 (CET) IronPort-PHdr: 9a23:EkcrBhSGvH/2RiNemM1b+lU9L9psv+yvbD5Q0YIujvd0So/mwa64bBKN2/xhgRfzUJnB7Loc0qyN4/6mCDJLvsnJmUtBWaIPfidNsd8RkQ0kDZzNImzAB9muURYHGt9fXkRu5XCxPBsdMs//Y1rPvi/6tmZKSV3BPAZ4bt74BpTVx5zukbvipduCPU4X23KUWvBbElaflU3prM4YgI9veO4a6yDihT92QdlQ3n5iPlmJnhzxtY+a9Z9n9DlM6bp6r5YTGY2zRakzTKRZATI6KCh1oZSz7ViQBTeIs0EBVGUflBUAJwmNuAvnWJf4tCTSru1mxCSde8v7UeZndy6l6vJNSRTrwA0KKyI06mDbhcE42KZauw664Rp+yI2SaoyJKPdkf6/ScPsVQGNAWoBaUCkXUdD0VJcGE+dUZbUQlIL6vVZb6ELmXQQ= Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=lists.nick.betteridge@gmail.com; spf=Pass smtp.mailfrom=lists.nick.betteridge@gmail.com; spf=None smtp.helo=postmaster@mail-wm0-f50.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of lists.nick.betteridge@gmail.com) identity=pra; client-ip=74.125.82.50; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="lists.nick.betteridge@gmail.com"; x-sender="lists.nick.betteridge@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of lists.nick.betteridge@gmail.com designates 74.125.82.50 as permitted sender) identity=mailfrom; client-ip=74.125.82.50; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="lists.nick.betteridge@gmail.com"; x-sender="lists.nick.betteridge@gmail.com"; 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@mail-wm0-f50.google.com) identity=helo; client-ip=74.125.82.50; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="lists.nick.betteridge@gmail.com"; x-sender="postmaster@mail-wm0-f50.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0AeAgAfC51WlDJSfUpehHmIVqFshwmMQIYPAoE0PBABAQEBAQEBARABAQEBBwsLCR8wgi2CCAEBBBIRBBkBGxwBAQMMBgULDQICBRYLAgIJAwIBAgEREQEFARwGDQgBARcHh2MBAxIEoH+BMT4xi0iBaoJ5hwAKGScNVoJxAQEBAQEBAQEBAQEBAQEBARcBBQoEcopUhFWDH4FJBZcajV+BXoc+DoVXimyCJTWBFzmCMCKBZHKHPAEBAQ X-IPAS-Result: A0AeAgAfC51WlDJSfUpehHmIVqFshwmMQIYPAoE0PBABAQEBAQEBARABAQEBBwsLCR8wgi2CCAEBBBIRBBkBGxwBAQMMBgULDQICBRYLAgIJAwIBAgEREQEFARwGDQgBARcHh2MBAxIEoH+BMT4xi0iBaoJ5hwAKGScNVoJxAQEBAQEBAQEBAQEBAQEBARcBBQoEcopUhFWDH4FJBZcajV+BXoc+DoVXimyCJTWBFzmCMCKBZHKHPAEBAQ X-IronPort-AV: E=Sophos;i="5.22,312,1449529200"; d="scan'208";a="160790822" Received: from mail-wm0-f50.google.com ([74.125.82.50]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 18 Jan 2016 17:02:13 +0100 Received: by mail-wm0-f50.google.com with SMTP id u188so109761066wmu.1 for ; Mon, 18 Jan 2016 08:02:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=4dhBrDnHxr6fo4r0AZs7+cXj7gQ1aKXbl6BNtnxGYMQ=; b=0i+19tbifG73FqwKdrziAQzwAJCF5XWSppnrAzMaVkt/HcTL1q5UdqFzNkFrXKOhWb rbAI14Nyiapqn+x8YnRahHULHICQ6FAJe6WyVh+86IljXWl6MLLElaU+VVnh2DQWsNsL P2DlZm2jyLWoFGguxrQWrgrQF7REQc+0ngLk5ARK5PASDEz/tQ5gSBhJ7HpROtaMfw1k 42JUYfwgQXzF0Wicraqc2qyIvwpIkz7gGhBT5kIMV5vgBDSwZ1O1oTM5k0mskzic1IkT /s0oN+WuheSUvsCDswtxSf0QroNvhVmrgKsDDV5zUJZ2WQ441RBP/hc9WAeAnLlmD6Or qbWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=4dhBrDnHxr6fo4r0AZs7+cXj7gQ1aKXbl6BNtnxGYMQ=; b=kd5xetu/jvh2ZJwa5HYuC5jIFJoConND0lT9FkD8V+wFSeIDKLtqJzpDmNIMq64Dxx lKF9eJrNgOUndgVyua5bs7nQNShml9MuhiJSn8yBqCPz9VK0PGTq1f2awRhFw4p+Bjck I1+3E2PFd+x/MNZcSvmGnvD312NVKN2bhMiAOSuT9tYsCL3837Uig7t9D6fI9ZdOQiO0 D2y/JFb9sR7hoRQBmBx/4q+R0AZxzdfpq/aTF6uUY7p60BhPS9CZxe6S92sRJhQCY/zT kP6k0X7fVTY5hld4aLrvuOZ8LKu3BJRKwZoZbkLLRuhLsCCd2SBA6MlZbICS+xS+xs2j 91xQ== X-Gm-Message-State: ALoCoQlJhRZpf1C9+GXfxgTgj8Swd2zcaVB/uMNqZnM4W3EZufHTscwg4aFlxp3ARYk1PxxjQoeHAxG74K6TsNEIPygVqCkYbw== X-Received: by 10.194.2.243 with SMTP id 19mr29654374wjx.154.1453132932752; Mon, 18 Jan 2016 08:02:12 -0800 (PST) Received: from [192.168.1.12] (buzzheavyyear.plus.com. [80.229.27.245]) by smtp.gmail.com with ESMTPSA id z65sm16386831wmg.10.2016.01.18.08.02.11 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 18 Jan 2016 08:02:11 -0800 (PST) To: Runhang Li References: <569782FC.1020904@gmail.com> <569C9915.4060707@gmail.com> <90FAD129-B205-45BE-8D92-9D3AF1D388CE@posteo.net> Cc: Nicolas Ojeda Bar , caml-list@inria.fr From: Nick Betteridge X-Enigmail-Draft-Status: N1110 Message-ID: <569D0C82.5070505@gmail.com> Date: Mon, 18 Jan 2016 16:02:10 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <90FAD129-B205-45BE-8D92-9D3AF1D388CE@posteo.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] Referencing a functor type Hi, Really grateful for help on this and thanks for taking time to write back. Octachron has just emailed me to suggest swapping two lines to make sure the type system knows that the existential type local_t inside cm1 and l_k1 are the same (from my original example) - ie: let module C1' = (val cs1' : Cipher with type local_t = 'a) in let LK (local1', cs1') = l_k1 in let signature = C1'.local_sign local1' (Cstruct.create 23) in should be let LK (local1', cs1') = l_k1 in let module C1' = (val cs1' : Cipher with type local_t = 'a) in let signature = C1'.local_sign local1' (Cstruct.create 23) in Your solution, of course :) , also works - what exactly does the '_' do in: type _ local_key - am I right in thinking that this was how the type system figured everything out? Thanks again for your time, Cheers Nick On 18/01/16 14:45, Runhang Li wrote: > module Cstruct = struct > type t = string > let create n = Obj.magic () > end > > module type Cipher = sig > > type local_t > type remote_t > > val local_create : unit -> local_t > val local_sign : local_t -> Cstruct.t -> Cstruct.t > val remote_create : Cstruct.t -> remote_t > val remote_validate : remote_t -> Cstruct.t -> bool > > end > > module MMMake_cipher (Cipher_impl : Cipher) = struct > type local_t = Cipher_impl.local_t > type remote_t = Cipher_impl.remote_t > > let local_create = Cipher_impl.local_create > let local_sign = Cipher_impl.local_sign > let remote_create = Cipher_impl.remote_create > let remote_validate = Cipher_impl.remote_validate > end > > > type _ local_key = > LK : 'a * (module Cipher with type local_t = 'a) -> 'a local_key > > type local_key_list = > | KNil : local_key_list > | KCons : 'a local_key * local_key_list -> local_key_list > > type _ cipher_module = > CM : (module Cipher with type local_t = 'a) -> 'a cipher_module > > type cipher_module_list = > | MNil : cipher_module_list > | MCons : 'a cipher_module * cipher_module_list -> cipher_module_list > > type self_t = { > mutable modules : cipher_module_list; > mutable locals : local_key_list > } > > module Cipher1 : Cipher = struct > type local_t > type remote_t > let local_create = fun _ -> Obj.magic () > let local_sign = fun _ _ -> Obj.magic () > let remote_create = fun _ -> Obj.magic () > let remote_validate = fun _ _ -> Obj.magic () > end > > module Cipher2 : Cipher = struct > type local_t > type remote_t > let local_create = fun _ -> Obj.magic () > let local_sign = fun _ _ -> Obj.magic () > let remote_create = fun _ -> Obj.magic () > let remote_validate = fun _ _ -> Obj.magic () > end > > module C1x = MMMake_cipher(Cipher1) > module C2x = MMMake_cipher(Cipher2) > > > let () = > let cs1 = (module C1x : Cipher with type local_t = Cipher1.local_t) in > let cs2 = (module C2x : Cipher with type local_t = Cipher2.local_t) in > let module C1 = (val cs1 : Cipher with type local_t = Cipher1.local_t) in > let module C2 = (val cs2 : Cipher with type local_t = Cipher2.local_t) in > let local1 = C1.local_create () in > let local2 = C2.local_create () in > let l_k1 = LK (local1, cs1) in > let l_k2 = LK (local2, cs2) in > let cm1 = CM (cs1) in > let cm2 = CM (cs2) in > ignore (C1.local_sign local1 (Cstruct.create 23)); > let self = { > modules = MCons (cm1, MCons(cm2, MNil)); > locals = KCons (l_k1, KCons(l_k2, KNil)); > } in > let CM cs1' = cm1 in > let module C1' = (val cs1' : Cipher with type local_t = 'a) in > let LK (local1', cs1') = l_k1 in > let signature = C1'.local_sign local1' (Cstruct.create 23) in > Printf.printf "OK"