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 4E1A580211 for ; Wed, 13 Sep 2017 20:57:41 +0200 (CEST) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=mjambon@gmail.com; spf=Pass smtp.mailfrom=mjambon@gmail.com; spf=None smtp.helo=postmaster@mail-pf0-f193.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of mjambon@gmail.com) identity=pra; client-ip=209.85.192.193; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="mjambon@gmail.com"; x-sender="mjambon@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of mjambon@gmail.com designates 209.85.192.193 as permitted sender) identity=mailfrom; client-ip=209.85.192.193; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="mjambon@gmail.com"; x-sender="mjambon@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-pf0-f193.google.com) identity=helo; client-ip=209.85.192.193; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="mjambon@gmail.com"; x-sender="postmaster@mail-pf0-f193.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AXN0vLBULedpZr7FdUrhK5K5dVK3V8LGtZVwlr6E/?= =?us-ascii?q?grcLSJyIuqrYZRGCt8tkgFKBZ4jH8fUM07OQ6P+wHzFYqb+681k8M7V0Hycfjs?= =?us-ascii?q?sXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aSV3DMl9+?= =?us-ascii?q?L+HxX4rTlNif1uao+pSVbR8bqiC6ZOZXJQ+qrAOZlMATi4xkYvI0yBLMqHxOU+?= =?us-ascii?q?tTzGJsY1mUmkCvtY+L4Jd//nEI6Loa/MlaXPCicg=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0CyCAC8frlZZMHAVdFdHQEFAQsBGAEFA?= =?us-ascii?q?QsBgy8jgVaDd5pHgUkJIoksjw4KhT4ChFVDFAEBAQEBAQEBAQEBAxoLDAUqL4I?= =?us-ascii?q?zIoJEAQUjFQgBGx4DDAYFCw0CAiYCAiMRAQUBHBMGAgEBF4l9AQMVoHFAjAuCB?= =?us-ascii?q?QUBHIMKBYNbChknDVeDFQEBAQEBBQEBAQEBGwIGCQEIfIIdggKBUIIOC4JyhUS?= =?us-ascii?q?CR4JhBZI4jkGUU4tEEYcflQMCBAIEBQIGFCSBFTaBLjIhCBwVShqEcIIyVotfA?= =?us-ascii?q?QEB?= X-IPAS-Result: =?us-ascii?q?A0CyCAC8frlZZMHAVdFdHQEFAQsBGAEFAQsBgy8jgVaDd5p?= =?us-ascii?q?HgUkJIoksjw4KhT4ChFVDFAEBAQEBAQEBAQEBAxoLDAUqL4IzIoJEAQUjFQgBG?= =?us-ascii?q?x4DDAYFCw0CAiYCAiMRAQUBHBMGAgEBF4l9AQMVoHFAjAuCBQUBHIMKBYNbChk?= =?us-ascii?q?nDVeDFQEBAQEBBQEBAQEBGwIGCQEIfIIdggKBUIIOC4JyhUSCR4JhBZI4jkGUU?= =?us-ascii?q?4tEEYcflQMCBAIEBQIGFCSBFTaBLjIhCBwVShqEcIIyVotfAQEB?= X-IronPort-AV: E=Sophos;i="5.42,389,1500933600"; d="scan'208";a="237387079" Received: from mail-pf0-f193.google.com ([209.85.192.193]) by mail3-smtp-sop.national.inria.fr with ESMTP; 13 Sep 2017 20:57:40 +0200 Received: by mail-pf0-f193.google.com with SMTP id i23so436739pfi.2 for ; Wed, 13 Sep 2017 11:57:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=A5GwW5lMgPiaPafkGOnKeWMhuExt8IswJnEWpPcn9R4=; b=N+H+x1k/QDj5PIGRLVA9RvZWSka0eyeVQyzma4oTQpyv9ntbFHmG0Gd5D95U1RNF3f XHewD3kGkifuWre7a+mLpZzq8IQVAtlt+gYECwjuOAIIwPsh+ANEHinPEUY7sg9vKo9A 9qqy1R30GEgNhP1FoT3aRsRWvhBP5kIc2/D09OzmkTF9mp5lFX0q30ko6JC4zoeR7/tx AUYrQRFa451dQ5c73J/hWypS510dX7VVQ/rIhh/tMk7Ay3v6LKjp19HyTLyPG/UNjZw6 x+XYBrV6F6M/1VwhKfWe33ok2lwVB2TUOjHsKMx9OS9GROwp20FgVroo+JlASaWABhbz 92Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=A5GwW5lMgPiaPafkGOnKeWMhuExt8IswJnEWpPcn9R4=; b=bDoHnEjRl453aB8G5m7kBEjolgB5IcDoGuM6qN6uxEJxyEelYTfUle96fwAB295d7D D2K5mCgu+5lwYVkNLyunay9r6KDhnZDvWx8JcRUtrndnJa9HvLC0MShCdw30tzbWlHYo s+8Je7wVZjFBaZO0cuPINHfKmomfjfjMbPo4cU4JeK9qmeG8m4tnwnFaVsv9BXEhXktX 50k5aFEMlIYtbG1c9xErSAonHpZ9zA9yjGx5yzBK7aX/Rh2YKx2YGeDc3+vr3TFSmpK1 AQwxtp8lhqCSxRVwdnwVOSqKn4gWDojIn9O9PZZAib3mSGsExebIrdqNYAqJSd9VcDU2 MyeA== X-Gm-Message-State: AHPjjUiY+lJbyucuWo/6XXGzDh17R5mILpABqySyZphaC2TmlhYkqlQZ 7QD+FWqPhnpxm2Nw1ac= X-Google-Smtp-Source: ADKCNb6sm0XDL/aiOMrIg2QcIXIJEO6oZgraPTKheaXjYjud2srEq6KPmkrYAGpVN3pVJxIVOiJ9cQ== X-Received: by 10.84.130.9 with SMTP id 9mr21341284plc.241.1505329058553; Wed, 13 Sep 2017 11:57:38 -0700 (PDT) Received: from [10.1.10.13] (c-73-189-41-37.hsd1.ca.comcast.net. [73.189.41.37]) by smtp.gmail.com with ESMTPSA id l25sm27967959pfj.141.2017.09.13.11.57.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Sep 2017 11:57:37 -0700 (PDT) To: caml-list@inria.fr References: <21484041-b7ed-33f0-4434-6817a82289fe@lexifi.com> From: Martin Jambon Message-ID: <9b22131c-bdfc-3003-23e9-b3a7c06ef34f@gmail.com> Date: Wed, 13 Sep 2017 11:57:36 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Validation-by: martin@mjambon.com Subject: Re: [Caml-list] Default value in module On 09/12/2017 02:49 PM, Paul A. Steckler wrote: > On Tue, Sep 12, 2017 at 5:40 PM, Alain Frisch wrote: >> What would be allowed as a default value is not completely clear (you don't >> want to carry runtime values with module types). > > Yes, propagating the default value sounds like the main implementation obstacle. A possible solution inspired from atdgen is to support only expressions that come with no uncertain dependency and no "computation", i.e. literal constants of core types. Core types here would include unit, bool, int, float, string, and list/option of a core type, and a few more (int64 etc.) and would exclude mutable values, records, variants other than list/option, and objects. Then we could write, using atd's conventions for `~` and `?`: module type A = sig val ~x : int = 42 (* just a literal, whose type can be inferred syntactically *) end module A1 : A = struct let x = 17 end module A2 : A = struct (* implicit `let x = 42` *) end Additionally, we could also have canonical defaults: bool: false int: 0 float: 0. string: "" option: None list: [] These being common and intuitive defaults, it makes sense to support them. So we could write: module type A = sig val ~x : int end module A1 : A = struct let x = 17 end module A3 : A = struct (* implicit `let x = 0` *) end I think this feature would be most useful if it was supported on record types. A record definition equivalent to the module signature above would be: type a = { ~x: int; (* default value is 0 *) ~y: int = 42; (* default value is 42 *) ?z: int option; (* default value is None *) } let a1 : a = {} (* equals `{ x = 0; y = 42; z = None }` *) Martin