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 605CB7EE5B for ; Sun, 25 May 2014 15:58:54 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.128.176; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.128.176 as permitted sender) identity=mailfrom; client-ip=209.85.128.176; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@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-ve0-f176.google.com) identity=helo; client-ip=209.85.128.176; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-ve0-f176.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsYBAPn2gVPRVYCwlGdsb2JhbABZDoNLWIJqqUWBB5ROAXsIFg4BAQEBBwsLCRIqgiUBAQEEEhEdARsSCwEDDAYFCw0CAgkdAgIiAREBBQEKEgYTEhCICwEDEQ2nDWqLJ4Fygw2YSwoZJwMKZIU2EQEFDIEejDsBOTMHgnWBSwSEXgWVEIE9j3kYKYQoQjsvAYEJ X-IPAS-Result: AsYBAPn2gVPRVYCwlGdsb2JhbABZDoNLWIJqqUWBB5ROAXsIFg4BAQEBBwsLCRIqgiUBAQEEEhEdARsSCwEDDAYFCw0CAgkdAgIiAREBBQEKEgYTEhCICwEDEQ2nDWqLJ4Fygw2YSwoZJwMKZIU2EQEFDIEejDsBOTMHgnWBSwSEXgWVEIE9j3kYKYQoQjsvAYEJ X-IronPort-AV: E=Sophos;i="4.98,906,1392159600"; d="scan'208";a="63892381" Received: from mail-ve0-f176.google.com ([209.85.128.176]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 25 May 2014 15:58:37 +0200 Received: by mail-ve0-f176.google.com with SMTP id jz11so8214193veb.35 for ; Sun, 25 May 2014 06:58:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=VttEHxHmjs64usLHHv0NnuR845g4i3OzOO673XGO2z8=; b=myBaB6ihGBojP4e87k5uhxkZyxNVomoMRFt5KS0piRI4rZXYzhxDk0jgpSA7/uCL6Y MUIDgDKEWrZ4FaQjLSuywQcxFugdh5LoOuyCB7lYZdwxglzJaVHTWnYBuvBD0dvDv5sf QbfB3rrvOFQYc5MvpkkvUXakFh4H1IPCu8wucYUVowxInBfcviwinaK6UeiIGGwGCc7R nIM8r7J2RJGp3VWMPGBiXKQKOv7n/gGArZ7bxWtDroU8Xe2QexPrAhExL829e42bkT7x h4b0AbGLEIkipF2tSosKKsX302gYxsfc7u7kBvwWOHTWbj9mVe72yS9El+8VfZf2D6YG bZ9g== X-Received: by 10.52.27.170 with SMTP id u10mr238099vdg.69.1401026315879; Sun, 25 May 2014 06:58:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.58.90.227 with HTTP; Sun, 25 May 2014 06:57:55 -0700 (PDT) In-Reply-To: <15117B8E-A404-4911-AC68-769CDF00B22E@my.bristol.ac.uk> References: <52C51721-8564-472C-AA7A-2ABE66C4D809@my.bristol.ac.uk> <20140525105906.GB7716@kerneis.info> <15117B8E-A404-4911-AC68-769CDF00B22E@my.bristol.ac.uk> From: Gabriel Scherer Date: Sun, 25 May 2014 15:57:55 +0200 Message-ID: To: Ollie Frolovs Cc: Gabriel Kerneis , caml users Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Modules and record fields The presence or absence of a warning is unrelated to whether it's a local module or a separate file. Solarized.orange.r and Solarized.(orange.r) are not equivalent. Solarized.orange.r means that you access the field "r" (in the current scope) of the value Solarized.orange. Solarized.(orange.r) opens Solarized locally for both the resolution of the "orange" identifier and "r" field name. Your new version is equivalent (Solarized's opening scope is even wider). The warning comes from the fact that since 4.01, OCaml can resolve a field name not only by having its path given from the current scope (eg. Solarized.r), but also by reasoning on the type of the record value, even if the field name itself is not in scope. Accessing field names that are not in scope is considered bad practice, hence the warning (which is disabled by a few people that like this style). On Sun, May 25, 2014 at 2:46 PM, Ollie Frolovs wrote: > It does, but I am rather disturbed by the compiler warning. I usually aim= not to have them, particularly when I am new to the language, assuming tha= t they at least hint at unsafe programming techniques. > > Update: I=E2=80=99ve put Solarized interface and definitions into separat= e files (rather than having both as module Solarized =3D =E2=80=A6 in the m= ain file) and there is no warning anymore for some reason. Unless there is= something else I=E2=80=99m doing differently without realising it. > > I suppose that solves my problem. Thanks everybody! > > solarize.mli: > > type colour =3D {r:int; g:int; b:int} > val base03 : colour > val orange : colour > > (* END *) > > solarize.ml: > > type colour =3D {r:int; g:int; b:int} > let base03 =3D {r=3D0x00; g=3D0x2b; b=3D0x36} > let orange =3D {r=3D0xcb; g=3D0x4b; b=3D0x16} > > (* END *) > > main.ml: > > =E2=80=A6 > Solarized.(Sdl.set_render_draw_color ren orange.r orange.g orange.b 0xff) > =E2=80=A6 > (* END *) > > > On 25 May 2014, at 11:59, Gabriel Kerneis wrote: > >> On Sun, May 25, 2014 at 11:30:20AM +0100, Ollie Frolovs wrote: >>> let module S =3D Solarized in >>> Sdl.set_render_draw_color ren S.orange.r S.orange.g S.orange.b 0xff >>> (* etc etc *) >> >> Doesn't this work with the latest version of the compiler? (with a >> warning "r is not visible in the current scope, and will not be >> selected if the type becomes unknown") >> >> -- >> Gabriel > > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs