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 6E2BD7FA5E for ; Tue, 16 May 2017 19:05:06 +0200 (CEST) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=ivg@ieee.org; spf=Pass smtp.mailfrom=ivg@ieee.org; spf=None smtp.helo=postmaster@mail-yw0-f177.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of ivg@ieee.org) identity=pra; client-ip=209.85.161.177; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ivg@ieee.org"; x-sender="ivg@ieee.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of ivg@ieee.org designates 209.85.161.177 as permitted sender) identity=mailfrom; client-ip=209.85.161.177; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ivg@ieee.org"; x-sender="ivg@ieee.org"; 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-yw0-f177.google.com) identity=helo; client-ip=209.85.161.177; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="ivg@ieee.org"; x-sender="postmaster@mail-yw0-f177.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3Awyuq/RNJRS9TNjWOgrcl6mtUPXoX/o7sNwtQ0KIM?= =?us-ascii?q?zox0LPT5rarrMEGX3/hxlliBBdydsKMYzbKO+4nbGkU4qa6bt34DdJEeHzQksu?= =?us-ascii?q?4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1?= =?us-ascii?q?Ov71GonPhMiryuy+4ZPebgFHiTanfb9+MAi9oBnMuMURnYZsMLs6xAHTontPde?= =?us-ascii?q?RWxGdoKkyWkh3h+Mq+/4Nt/jpJtf45+MFOTav1f6IjTbxFFzsmKHw65NfqtRbY?= =?us-ascii?q?UwSC4GYXX3gMnRpJBwjF6wz6Xov0vyDnuOdxxDWWMMvrRr0yRD+s7bpkSAXwhS?= =?us-ascii?q?gFOT438G/ZhM9tgqxFvB2svAZwz5LObYyPKPZyYqHQcNUHTmRBRMZRUClBD5u/?= =?us-ascii?q?YYsRFeUBO/tToYj6p1sSqhu+GxWjBOPuyj9UnX/9wKo30+U/EQHJxwEgHswBv2?= =?us-ascii?q?rKo9nvM6cSS++1wbDOwD7ebP1WwS/w5JbUfh0lu/2BXrJ9fdDMxUQuCg/JlEic?= =?us-ascii?q?pI7nMj6Ty+8DqXKU7/B6WuKqk2Mnqx9+ojyoxso0j4nGnIMVylTd+SR5zoc5Oc?= =?us-ascii?q?S0SEBmbdOmEpZcrS6aN4xxQsMtR2Fnpjw2xaEBuZ6+ZCQKyZInyADDa/GfbYSE?= =?us-ascii?q?/hbuWPySLDp4nn5pZbOyiwuo/US9yODxVNG40FNQoSpEltnMuGoN1xvW6sWfS/?= =?us-ascii?q?t94Eih1C2O1w/N9O5LP1o4la3BK54u2rIwjIYcsVzfHi/qn0X7lLOZeV8h+uis?= =?us-ascii?q?8ujnZrTmpoSAN4JvkQH/MqEumtSlDugiMwgOWXKb+eWm27H58035WuYCsvpjrq?= =?us-ascii?q?jc+LTXIsISvKLxVzNU164/6hO7AjCg2c4U22QcegFrYhWC2qn3MleGD/fkCum0?= =?us-ascii?q?g1Wwi38/xu7JFrzsD5iLKWLMxuSyNY1h4lJRnVJghetU4IhZX+kM?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0BDAQB8MBtZh7GhVdFcHAEBBAEBCgEBG?= =?us-ascii?q?AEFAQsBhRgHg2WBNohikWWVdYIPhiQChUYHPxgBAQEBAQEBAQEBARIBAQEIDQk?= =?us-ascii?q?IKC+CMyKCRAECAgEjBBkBATcBBAsJAgQHGh0CAiISAQUBHAYTihYFCI5ckRo/i?= =?us-ascii?q?x1qgWw6gwkBAQWHcgEBAQEBAQQBAQEBAQEBGQgShk2EeYd1gmABng6TG5Frkns?= =?us-ascii?q?UH4EVH4FCfQhGGQaESQwTDIF/JDYBiEIBAQE?= X-IPAS-Result: =?us-ascii?q?A0BDAQB8MBtZh7GhVdFcHAEBBAEBCgEBGAEFAQsBhRgHg2W?= =?us-ascii?q?BNohikWWVdYIPhiQChUYHPxgBAQEBAQEBAQEBARIBAQEIDQkIKC+CMyKCRAECA?= =?us-ascii?q?gEjBBkBATcBBAsJAgQHGh0CAiISAQUBHAYTihYFCI5ckRo/ix1qgWw6gwkBAQW?= =?us-ascii?q?HcgEBAQEBAQQBAQEBAQEBGQgShk2EeYd1gmABng6TG5FrknsUH4EVH4FCfQhGG?= =?us-ascii?q?QaESQwTDIF/JDYBiEIBAQE?= X-IronPort-AV: E=Sophos;i="5.38,350,1491256800"; d="scan'208,217";a="223854318" Received: from mail-yw0-f177.google.com ([209.85.161.177]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 16 May 2017 19:05:05 +0200 Received: by mail-yw0-f177.google.com with SMTP id l74so41591094ywe.2 for ; Tue, 16 May 2017 10:05:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ieee-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=1Cqx5K1+kG8Soo5x+QIwMjbRioTH5UxvttUUcrMmMPk=; b=Qy3rpBp6pTtS6ZBlFbQSmR+mxccTg8kGRVfoB9Io6PGyydKwKgLwNihrK17x+PBoKB Oar0cvm5C3ZGxljNIrJfly87ILHb3bkdFf/ACAPMzN/sKk2FDyvyYbYMuElepZplpTwi Xp94xOcV3DujWk40Moemc1+XR4Sxejjrh9uDLJMPxBa2nUMoKQSup1NuHQ3KQQG0TMCh o6prMFk8/AVXY3F8tpeWuudJXVi5CEBxv/JfGYZqYYKQ/JIZOMeo+/46GMRQqxTaey7S OvEF5YtWAiBloj20jtSjzzWWuyHcdgV8XIXud2IvIQ/vg2t/uaAGoOxxw+AMKmUu1EE/ ytHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=1Cqx5K1+kG8Soo5x+QIwMjbRioTH5UxvttUUcrMmMPk=; b=XYeo4IamQJ4zYkYG2UlA24A3eEUM/ITmIpdgJcudPiH1mtOwE8uzqzK43dyw5DW08n 04QKdP/ecrUlfv7SCFH57TiE0H0/v9J2V8WMQHfY2au6Zepu0rGyhin6EAt7L4g/XRXs qDGGNNzEcVisJ0eR9QXyCqcFJuq57e4THeqlKe/OJwtsK7EXOjpsbJmqwBv0WeQXlrgU Mjilo/+calzUS5on6dUJiJXRnuCXWUv9tiv+OMDLEdVA3nBFR9rj4+p7tOp+5WGyyQIr b90zWpMOEo90EPPiiJoyC7TyQPJjWZzjre4s1f+63gOx9vIRYpkx2ItwE3FHE2jNzv/k s5Hg== X-Gm-Message-State: AODbwcA98G4/qy9nX+Ph9noAbWngIo/4FoPlvqSmgSA6WOYo2LkU4wnB 4SihyZRQSsv8KaD6JxwfWPNzlP/zNxrv X-Received: by 10.13.232.129 with SMTP id r123mr11130791ywe.161.1494954303593; Tue, 16 May 2017 10:05:03 -0700 (PDT) MIME-Version: 1.0 Received: by 10.129.130.66 with HTTP; Tue, 16 May 2017 10:05:03 -0700 (PDT) In-Reply-To: References: From: Ivan Gotovchits Date: Tue, 16 May 2017 13:05:03 -0400 Message-ID: To: Tim Leonard Cc: caml-list Content-Type: multipart/alternative; boundary="94eb2c08282438de15054fa72c6b" Subject: Re: [Caml-list] type inference of record field that is an array --94eb2c08282438de15054fa72c6b Content-Type: text/plain; charset="UTF-8" Hi Tim, The `x.[i] <- v` syntax maps to `String.set` function, that has type `string -> char -> unit`, the array subscription syntax uses parentheses instead of the brackets. So in your case, it should be x.array_field.(1) <- 3 If you are concerned with the warning, that is emitted before the error. Then this is expected, as `x.[i] <- v` is a syntactic sugar to the `String.set` and it is translated on the lexing level. Thus the type checker never sees the array/string/bigarray subscript operators (as they are not present in the AST) Regards, Ivan On Tue, May 16, 2017 at 12:58 PM, Tim Leonard wrote: > Is type inference working as expected here, or is this a bug? > > # type record_type = { array_field : int array };; > type record_type = { array_field : int array; } > # let test_function_1 x = Array.set x.array_field 1 3;; > val test_function_1 : record_type -> unit = > # let test_function_2 x = x.array_field.[1] <- 3;; > Characters 24-46: > let test_function_2 x = x.array_field.[1] <- 3;; > ^^^^^^^^^^^^^^^^^^^^^^ > Warning 3: deprecated: String.set > Use Bytes.set instead. > Characters 24-37: > let test_function_2 x = x.array_field.[1] <- 3;; > ^^^^^^^^^^^^^ > Error: This expression has type int array > but an expression was expected of type bytes = string > # > --94eb2c08282438de15054fa72c6b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Tim,

The `x.[i] <- v` synta= x maps to `String.set` function, that has type `string -> char -> uni= t`, the array subscription syntax uses parentheses instead of the brackets.= So in your case, it should be

=C2=A0 =C2=A0 x.array_fie= ld.(1) <- 3


If you are concerned= with the warning, that is emitted before the error. Then this is expected,= as `x.[i] <- v` is a syntactic sugar to the `String.set` and it is tran= slated on the lexing level. Thus the type checker never sees the array/stri= ng/bigarray subscript operators (as they are not present in the AST)
<= div>
Regards,
Ivan=C2=A0

On Tue, May 16, 2017 at 12:58 PM= , Tim Leonard <Tim@timleonard.us> wrote:
Is type inference w= orking as expected here, or is this a bug?

# type record_type = =3D { array_field : int array };;
type record_type =3D { array_field : int array; }
# let test_function_1 x =3D Array.set x.array_field 1= 3;;
val test_function_1 : reco= rd_type -> unit =3D <fun>
# let test_function_2 x =3D x.array_field.[1] <- 3;;
Characters 24-46:
=C2=A0 let test_function_2 x =3D x.array_field.[1] <- 3= ;;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ^^^^^^^^^^^^= ^^^^^^^^^^
Warning 3: deprecate= d: String.set
Use Bytes.set ins= tead.
Characters 24-37:<= /div>
=C2=A0 let test_function_2 x =3D x.arr= ay_field.[1] <- 3;;
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 ^^^^^^^^^^^^^
Error:= This expression has type int array
=C2=A0 =C2=A0 =C2=A0 =C2=A0but an expression was expected of type byte= s =3D string
#=C2=A0

--94eb2c08282438de15054fa72c6b--