From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 14BBFBC57 for ; Wed, 17 Mar 2010 18:04:55 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aq4BAF+ooEtDww+7kWdsb2JhbACDC4t0gXZ8iSwBAQEBCQsKBxMDH6ofN4FjhSmIeQEEBAGBJ4JgagSDGg X-IronPort-AV: E=Sophos;i="4.49,658,1262559600"; d="scan'208";a="47338144" Received: from web111510.mail.gq1.yahoo.com ([67.195.15.187]) by mail2-smtp-roc.national.inria.fr with SMTP; 17 Mar 2010 18:04:54 +0100 Received: (qmail 77999 invoked by uid 60001); 17 Mar 2010 17:04:52 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1268845492; bh=P9V1e74YOBWddGZNWIGWC+8zmwZN9t6hT7eAQV+9v7k=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=ZL3NqlpvwG771sIZ+s7O3O0nrjf+Q9Fu9Utud+4rErrwhlJah7W5RiL/v96HLbsLEwXJTHVLXUKyVabO4q79X6LYVfxb2TBlt4x2qmGRiEIZjce+NxLja2KKgs4KWgucw1cqe7NGPJ7+IE+u4nilfos/HImIQwMOTaHY2cbuZxo= DomainKey-Signature:a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=iAQ/7kJt1nZhDjpT7qZ7VyD7+Bf2bRTImZZaLf2ZAJ1P9CFp2NUcRkuJJ9HDFehAqaORUXEY9r3R2V+zgit/XQyzMz8kI9DUMigRgsXIbvHaZYwAX+Fa/GwTSxNr0uRV2/tD5PyAHZse4n48dOnxy/4ihnjMJACVk8SHUb5yMJE=; Message-ID: <571731.77500.qm@web111510.mail.gq1.yahoo.com> X-YMail-OSG: 20zEwLMVM1nRi0exk9uaNTEYqguSo_AxpEdmbGA6_hDgRjl yTteK5mpv3V8VIQBpG8ZAPkzqgbzzO9qQR8ui1rLd_14r33iDM.ajV35c4B7 3jFLoBcGOUKea_QU7eDvRflxqeDMBmSVFrdD.YUyfcxkQila6m8Ugb2Pg1FH kqHcTkIhJ5EJwZnnaDls5sh1QP7KbzJluIAa1lJWeoOlQXMB9oAL7ge9lH9F p17FgxoYQFH8cd2Y4aP7sLXtVr.Qd.RtbP.GhlH_IkV6vGiPv9hmxin4XBzF n_WgK2nGNYvU01_lwE_2k3m7Ml63KvRfed3DklrBi81rVono.1zoI Received: from [213.205.71.53] by web111510.mail.gq1.yahoo.com via HTTP; Wed, 17 Mar 2010 10:04:52 PDT X-Mailer: YahooMailClassic/10.0.8 YahooMailWebService/0.8.100.260964 Date: Wed, 17 Mar 2010 10:04:52 -0700 (PDT) From: Dario Teixeira Subject: Lazy modules To: caml-list@yquem.inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; semantics:01 functor:01 sig:01 sig:01 struct:01 sockaddr:01 sockaddr:01 foo:01 struct:01 runtime:01 functor:01 config:01 config:01 lazy:02 lazy:02 Hi,=0A=0AI've come across a problem which though novel to me, I presume mus= t be=0Afamiliar to those with more ML baggage. Namely, I need a module who= se=0Avalues are not known at the initialisation stage, since they can only= =0Abe determined after reading a configuration file. If this were a lone= =0Avalue, I would declare it as a lazy value which when forced would read= =0Afrom the configuration file. But how can I achieve similar semantics=0A= with a whole module? =0A=0AIn a sense I need a lazy module. Also, note tha= t I find the solution=0Aof declaring all values in that module as lazy a bi= t inelegant.=0A=0AI do have a solution which though hackish and relying on = a language=0Aextension (local modules) seems to work: I create the module o= n demand=0Avia a functor parameterised over an empty sig:=0A=0Amodule Socke= t_maker (S: sig end) : Client.SOCKET =3D=0Astruct=0A let sockaddr =3D !C= onfig.sockaddr=0A let sockdomain =3D !Config.sockdomain=0A let sockty= pe =3D !Config.socktype=0A let sockproto =3D !Config.sockproto=0Aend=0A= =0Alet foo =3D=0A let module Socket =3D Socket_maker (struct end) in=0A = ...=0A=0ABut I wonder a) what's the penalty associated with the runtime = application=0Aof the functor, and b) if there's some better way of doing th= is. Any thoughts?=0A=0AThanks for your time!=0ABest regards,=0ADario Teixe= ira=0A=0A=0A=0A