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 B2F3D7FA5E for ; Mon, 8 May 2017 20:32:05 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=cedilla@gmail.com; spf=Pass smtp.mailfrom=cedilla@gmail.com; spf=None smtp.helo=postmaster@mail-ua0-f179.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of cedilla@gmail.com) identity=pra; client-ip=209.85.217.179; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="cedilla@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of cedilla@gmail.com designates 209.85.217.179 as permitted sender) identity=mailfrom; client-ip=209.85.217.179; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="cedilla@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-ua0-f179.google.com) identity=helo; client-ip=209.85.217.179; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="postmaster@mail-ua0-f179.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3Ahx+MHxLiCy6uw9HHWdmcpTZWNBhigK39O0sv0rFi?= =?us-ascii?q?tYgQLfTxwZ3uMQTl6Ol3ixeRBMOAuq4C07KempujcFRI2YyGvnEGfc4EfD4+ou?= =?us-ascii?q?JSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgpp?= =?us-ascii?q?POT1HZPZg9iq2+yo9ZDeZwpFiCChbb9uMR67sRjfus4KjIV4N60/0AHJonxGe+?= =?us-ascii?q?RXwWNnO1eelAvi68mz4ZBu7T1et+ou+MBcX6r6eb84TaFDAzQ9L281/szrugLd?= =?us-ascii?q?QgaJ+3ART38ZkhtMAwjC8RH6QpL8uTb0u+ZhxCWXO9D9QLYpUjqg8qhrUgflhi?= =?us-ascii?q?cJOTA67W/ZlNB/gblBrx69vRFy2ZLYbJ2XOfd4Y6jTfckaRW1EXstJSyJOHJ2z?= =?us-ascii?q?YJYSBOUBPOZYq5L9p1wIrRCjAgSjGP3gxSJJhn/y2a01yf8sEQ7D3AM6HtIOtG?= =?us-ascii?q?7Yo8nyNKcXSO24yrTDwzbbb/5Oxzvx9IzFfgoirPyMR758b9fdxEs1Gw/YjFid?= =?us-ascii?q?rYroNC6P2OsXqWiU9e9gWPqvi2E5rwFxpSCixsI2hYnIgoIZ003E+j9lzIosK9?= =?us-ascii?q?20VUx2bNq+HJtfsCGaMIR2Qsc8TG1ypCk6zbgGtYa6fCgM1psn2wbSZ+Kbf4WM?= =?us-ascii?q?+B7uV+acLS1miH54er+znQu+/Eqkx+HkU8m7yldKri5LktnWsXAN0gTe5dSZRf?= =?us-ascii?q?Rg/0eh3TKP2BrI5+FLJEA7j6vbK5o7zrEskZoTtFzPHjXql0XukK+WakIk9/C0?= =?us-ascii?q?5Ov9Z7XmooaQN4t1igHlLqQjgde/AOQ9MggWRWeX4+W81Lv5/U34WrpGlPM2kr?= =?us-ascii?q?OK+KzdcM8So6r8Bw5Ozq4i7Qy+BnGoyoc2h34CeWhIdR7PsIntIFbIaKTzAPu+?= =?us-ascii?q?h1CluDhuzvHCeLbmB8OefTD4jL79cOMluAZnww0pwIUH6g=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0BSAwCVuBBZhrPZVdFcHhgHDBgHhQsHg?= =?us-ascii?q?2GaQQEBBoo4jGCCDw6KdgdAFwEBAQEBAQEBAQEBEgEBAQgLCwgoL4IzIIJsBBk?= =?us-ascii?q?BGx4DEgkBBjcCJAERAQUBijwBAwgNo0WDRT+MCIFsGAUBHIMKBYNXChknDVaDD?= =?us-ascii?q?AIGEoYHhQuFY4IEDC6CXwWRIoxXgVuRPZFsknYUH4EVIQKBPi8gCBkVX4Rrgg8?= =?us-ascii?q?gNohrAQEB?= X-IPAS-Result: =?us-ascii?q?A0BSAwCVuBBZhrPZVdFcHhgHDBgHhQsHg2GaQQEBBoo4jGC?= =?us-ascii?q?CDw6KdgdAFwEBAQEBAQEBAQEBEgEBAQgLCwgoL4IzIIJsBBkBGx4DEgkBBjcCJ?= =?us-ascii?q?AERAQUBijwBAwgNo0WDRT+MCIFsGAUBHIMKBYNXChknDVaDDAIGEoYHhQuFY4I?= =?us-ascii?q?EDC6CXwWRIoxXgVuRPZFsknYUH4EVIQKBPi8gCBkVX4Rrgg8gNohrAQEB?= X-IronPort-AV: E=Sophos;i="5.38,310,1491256800"; d="scan'208,217";a="272203760" Received: from mail-ua0-f179.google.com ([209.85.217.179]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 08 May 2017 20:32:04 +0200 Received: by mail-ua0-f179.google.com with SMTP id g49so49788407uaa.1 for ; Mon, 08 May 2017 11:32:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=PDKixhKwGDWMSVZfytCi9PpFzJQrqz1EGLKozG4EaX8=; b=tljIOkxyxtYAZm0uZ4XT3bnlu8HPQAkpBJhptQWcj9xQpXZ3rPdHWImFWNUvnlOEyZ DgLIo81n0vuHPyQvVRrEho1qGg8oAHXMsQFHbkg/Wmr1iFfHb8KCXHOzRgSG7d8atx+V oZgAsG2PaPkjG+NSCopyOCUwrCOboGHZyWdi7yYkLQjajobJU6HGcIg3XLWvTMzWTGSD sgxIHgTcwJ1cqIFZCtSSQBAgWN9ICgSVkozkbH8c4hTd3g7R3T4HVjrT2Wf0/y2+LeZE PvnvrnSUW7ZlRREjk//Xpva2vEXw4mwk/GDa7mDQG/zNhrlvbZSaxrh592LwkXyb6MIw y1bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=PDKixhKwGDWMSVZfytCi9PpFzJQrqz1EGLKozG4EaX8=; b=kWeFS8aTnJvyRpNQVEFuzB+VPT6wLhAIwNJ2XV6W7ccKREPeEuCjvDx0hIaIRYk/Tt 897yVS7SKX7ezSpPV76PAOcTBuQszkDEqP/DkST2q89cFOlqibFkLv3PEEKE8YnGi7eK wtb8LLU77ACLZP30lNjRkbKcjbI2QU7jPwBYHchuhjRUHNHM1HfCKlNemkdxwOUolpbh Votwn/1lcX5PIDhnYZOFHrfcNj8d9lxs2H039eAgEoLDcUbHtvdNMr7CbpXg/hi+MMXJ 6G0aytRVlsSi2IVOuRHYs+UpixkSpoPeRIOhhQFlgvTMM3fnR4a0HdUn9Z17QOdaEyMp SwlA== X-Gm-Message-State: AN3rC/5Jk+yVljWitBB/JGJluJ88FbT7bkm9ikYiwHfCaQFE71ZiGxtd tFRKQHOf69P3RngA/Dz6sIOzjvOVWrIf6wQ= X-Received: by 10.176.77.158 with SMTP id s30mr29591768uag.29.1494268323602; Mon, 08 May 2017 11:32:03 -0700 (PDT) MIME-Version: 1.0 Received: by 10.31.2.19 with HTTP; Mon, 8 May 2017 11:32:02 -0700 (PDT) From: Reed Wilson Date: Mon, 8 May 2017 11:32:02 -0700 Message-ID: To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=f40304378d80a0a801054f077409 X-Validation-by: cedilla@gmail.com Subject: [Caml-list] Type generalization confusion --f40304378d80a0a801054f077409 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I've been working with some of the new features introduced with GADTs, and ran into a confusing instance of the "type variables that cannot be generalized" error. The simplified program is as follows: type _ field =3D Int : int -> 'a field let a =3D Int 3 let b =3D Int (1 + 2) let inside =3D 1 + 2 let c =3D Int inside ocamlc -i returns: type _ field =3D Int : int -> 'a field val a : 'a field val b : '_a field val inside : int val c : 'a field with b remaining non-generalized. The problem I'm having with it is that the type variable doesn't depend on the value at all, so I don't see how that can prevent generalization. Also, the manual says the reason some types aren't generalized is due to "polymorphic mutable data structures". Nothing I created is mutable, so why was generalization turned off in the first place? Finally, I'm confused why separating the function from the definition is enough to fix this; c is generalized simply by defining 1+2 in a separate value (which must be global, apparently). Thanks, Reed Wilson --=20 =C3=A7 --f40304378d80a0a801054f077409 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I've been working with some of the new features introd= uced with GADTs, and ran into a confusing instance of the "type variab= les that cannot be generalized" error.

The simplifi= ed program is as follows:
type _ field =3D Int : int -> &= #39;a field
let a =3D Int 3
let b =3D Int (1 + 2)
let inside =3D 1 + 2
let c =3D Int inside

ocamlc -i returns:
type _ field =3D In= t : int -> 'a field
val a : 'a field
val b := '_a field
val inside : int
val c : '= ;a field

with b remaining non-generalized. T= he problem I'm having with it is that the type variable doesn't dep= end on the value at all, so I don't see how that can prevent generaliza= tion.

Also, the manual says the reason some types = aren't generalized is due to "polymorphic mutable data structures&= quot;. Nothing I created is mutable, so why was generalization turned off i= n the first place?

Finally, I'm confused why s= eparating the function from the definition is enough to fix this; c is gene= ralized simply by defining 1+2 in a separate value (which must be global, a= pparently).

Thanks,
Reed Wilson

--
=C3=A7
--f40304378d80a0a801054f077409--