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 639A2822AC for ; Fri, 17 Nov 2017 17:13:52 +0100 (CET) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=cedilla@gmail.com; spf=Pass smtp.mailfrom=cedilla@gmail.com; spf=None smtp.helo=postmaster@mail-wm0-f45.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of cedilla@gmail.com) identity=pra; client-ip=74.125.82.45; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="cedilla@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of cedilla@gmail.com designates 74.125.82.45 as permitted sender) identity=mailfrom; client-ip=74.125.82.45; receiver=mail3-smtp-sop.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 (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wm0-f45.google.com) identity=helo; client-ip=74.125.82.45; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="postmaster@mail-wm0-f45.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AZoXyih0zAcVO31VGsmDT+DRfVm0co7zxezQtwd8Z?= =?us-ascii?q?seseL/ad9pjvdHbS+e9qxAeQG96Eu7QZ06L/iOPJZy8p2d65qncMcZhBBVcuqP?= =?us-ascii?q?49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL2vpv2aq4DUONhL6PAtz?= =?us-ascii?q?bqSpS8+Bx/iwgue555TYYx9PgnLpZrhuJT2uqgHAvckRm4xkbKgrnEjnuHxNLt?= =?us-ascii?q?5byG8gGlOXhBH6rpO78ZJi9yBZk/0k/s9EF679evJrHvRjED06PjVtt4XQvh7Z?= =?us-ascii?q?QF7Tt3Y=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0C4BgApCg9ahi1SfUpbHQEBBQELAYNhA?= =?us-ascii?q?T5uJweDeIE2mA49BwEBBoEsBYJVhGSCFodKh1oKJYUWAoRgB0MUAQEBAQEBAQE?= =?us-ascii?q?BARIBAQEICwsIKC+COAUDBB6CPQECAgEjHQEbEgsBAwELBgMCCxodAgIiAREBB?= =?us-ascii?q?QEKEgYTEgmJcQEDCAUIEIwlkRtAjA2CBQUBHIMKBYNhChknAwpYgmMBAQEBAQE?= =?us-ascii?q?EAQEBAQEBAQEYAgYSgyKCB4EOhVuDJIIkgmiCYwEEiEkMijOGGokch3KNGoJ4k?= =?us-ascii?q?FSMcoksFAUfgRYPJ4IWNCEIHRVJNYIvCYIaKgwTDIIIIDYBiRSBQQEBAQ?= X-IPAS-Result: =?us-ascii?q?A0C4BgApCg9ahi1SfUpbHQEBBQELAYNhAT5uJweDeIE2mA4?= =?us-ascii?q?9BwEBBoEsBYJVhGSCFodKh1oKJYUWAoRgB0MUAQEBAQEBAQEBARIBAQEICwsIK?= =?us-ascii?q?C+COAUDBB6CPQECAgEjHQEbEgsBAwELBgMCCxodAgIiAREBBQEKEgYTEgmJcQE?= =?us-ascii?q?DCAUIEIwlkRtAjA2CBQUBHIMKBYNhChknAwpYgmMBAQEBAQEEAQEBAQEBAQEYA?= =?us-ascii?q?gYSgyKCB4EOhVuDJIIkgmiCYwEEiEkMijOGGokch3KNGoJ4kFSMcoksFAUfgRY?= =?us-ascii?q?PJ4IWNCEIHRVJNYIvCYIaKgwTDIIIIDYBiRSBQQEBAQ?= X-IronPort-AV: E=Sophos;i="5.44,410,1505772000"; d="scan'208,217";a="245029388" Received: from mail-wm0-f45.google.com ([74.125.82.45]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 17 Nov 2017 17:13:51 +0100 Received: by mail-wm0-f45.google.com with SMTP id l8so7401613wmg.4 for ; Fri, 17 Nov 2017 08:13:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=OlvW0013yt71X4wnND0cFU3Pc/oLmOiJc4VOR9hDsto=; b=RGIveAsoPK0EOVUfpVXqOSNuMrTj1UvpH9TRrUS79GS40jKat5nP0gYdGf0G8cTM9p /0lvG8scz8r0SP2sbOq2TUaoRRRRzMwXoQmDXx/rYZ3UqUpiPgyqOpnHjheu0pFT4l62 ke6v5LeEQ0fQFWjZqoG/QUcz7EyBtGA9fDwR1CVzhnJzsTVWytqB8zjVJfbOTxJe8olY cTDUQ146r2F/f1KOuAkxz8505DknKsfHu3n+R/kFTboFt1/6bTlm4LUAT+vn+z0iIuu1 H1akoRhM/i6/q2bg7BAj3Sc/8VJP+HZcSs4EpG0cz7cdMhXe7P6SLMZ/q9zRtuAUZqki 9jZw== 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=OlvW0013yt71X4wnND0cFU3Pc/oLmOiJc4VOR9hDsto=; b=TH9tQpEb9Aqhfo2tFD4r37waXVk84yRrGxDv71BRsZvQPoGHu0Qm/w/xW5z6YXuTDR K3aPBQuHumPavK4TuPvvcMWkNmUm1gKDqO4rCExa6YNGKwTfO+vU+H0TEQ/sMei+fEdB 5pVq7CFkNhuzsjlx9IKOi5GBooq2sskMyYeK+13TQ3gQJHR9WzBBkFJkzFh/TRHMudr7 jo4KBQsaoLkr3/dhdA1qKxqexssV2826uQgiWLUvdNulsIV0l2onCRwsR4diSD5Gt8+d xsZSCgadiu0SAONrFd5mcHoL+f0NQjTdJwQ0p5jQISJCZ+9pGd6XeMI6B8I9EGrZJNrr U2sA== X-Gm-Message-State: AJaThX4q9FKO37gCfo+1LDxP7wzvoLJVqPfKUH9kicHMadYYmldO3zPt MK0QutnD7I1GOlslAXlbuhtMl2jtJ6wfSSPP/DXmMn9jPeM= X-Google-Smtp-Source: AGs4zMaEfTiOAai45p+7Bc20wfJeE7agXQYSRZyInwOyCl2MLiCYAadt7pe5WsFZco3VD9lm+OlbMGoJjX8FQQUltQs= X-Received: by 10.80.217.15 with SMTP id t15mr8282039edj.217.1510935230615; Fri, 17 Nov 2017 08:13:50 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.245.226 with HTTP; Fri, 17 Nov 2017 08:13:49 -0800 (PST) In-Reply-To: <41144c60-9090-7159-c870-08ca5eb5c09e@polychoron.fr> References: <41144c60-9090-7159-c870-08ca5eb5c09e@polychoron.fr> From: Reed Wilson Date: Fri, 17 Nov 2017 08:13:49 -0800 Message-ID: To: octachron Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary="089e08224398b31409055e300589" X-Validation-by: cedilla@gmail.com Subject: Re: [Caml-list] Subtyping (or something like it) --089e08224398b31409055e300589 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I hadn't noticed that 4.06 will let me extend indexing. It's certainly a nice feature to have; I'll throw it in :) I actually think I can use that to great effect - a lot of this is used to pack data into structures which are sent to/from C, the network, files, etc.. Having multiple ways of indexing it could be quite helpful for getting/setting multiple different types of data. let ( .!{ } ) =3D get_1byte_int let ( .@{ } ) =3D get_2byte_int let ( .${ } ) =3D get_4byte_int let ( .*{ } ) =3D get_8byte_int Where the extension character is shift+number of bytes (at least on my keyboard...) I'm a bit worried that it'll start looking like Perl, but time will tell. Thanks for the great ideas! On Fri, Nov 17, 2017 at 5:01 AM, octachron wrote: > With OCaml 4.06, if what you really want is to have a nice syntax for > array indexing, one solution would be to define your own indexing operato= rs: > > let ( .%{ } ) a k =3D a.{k} > let ( .%{ } <- ) a k x =3D a.{k} <- x > > These operators can be used like standard indexing operators > > let x =3D a.%{ 0 } in > a.%{ 1 } <- x > > and exported with > > val ( .%{ } ): =E2=80=A6 > val ( .%{ } <- ): =E2=80=A6 > > Nevertheless, contrarily to Bigarray, there is no implicit conversion for > multidimensional array, > in other words > > a .%{0,1} > > will not work out of the box. > > However, if needed, it is possible to use qualified indexing operators to > circumvent this difficulty: > > module D1 =3D struct let ( .%{} ) a k =3D a.{k} end > module D2 =3D struct let ( .%{} ) a (k,l) =3D a.{k,l} end > let x_ij =3D mat.D2.%{i, j} > let x_0 =3D vector.D1.%{0} > > See also the manual for more details: http://caml.inria.fr/pub/docs/ > manual-ocaml/extn.html#s%3Aindex-operators . > > =E2=88=92 octachron. > > -- > 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 > --=20 =C3=A7 --089e08224398b31409055e300589 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I hadn't noticed that 4.06 will let me extend indexing= . It's certainly a nice feature to have; I'll throw it in :)
I = actually think I can use that to great effect - a lot of this is used to pa= ck data into structures which are sent to/from C, the network, files, etc..= Having multiple ways of indexing it could be quite helpful for getting/set= ting multiple different types of data.
let ( .!{ } ) =3D get_1byt= e_int
let ( .@{ } ) =3D get_2byte_int
let ( .${ } )= =3D get_4byte_int
let ( .*{ } ) =3D get_8byte_int
Wher= e the extension character is shift+number of bytes (at least on my keyboard= ...) I'm a bit worried that it'll start looking like Perl, but time= will tell.
Thanks for the great ideas!

On Fri, Nov 17, 2017 at 5:01 AM= , octachron <octa@polychoron.fr> wrote:
With OCaml 4.06, if what you really want is to have a nice s= yntax for array indexing, one solution would be to define your own indexing= operators:

=C2=A0 let (=C2=A0 .%{ } ) a k =3D a.{k}
=C2=A0 let ( .%{ } <- ) a k x =3D a.{k} <- x

These operators can be used like standard indexing operators

=C2=A0=C2=A0=C2=A0 let x =3D a.%{ 0 } in
=C2=A0=C2=A0=C2=A0 a.%{ 1 } <- x

and exported with

=C2=A0=C2=A0 val (=C2=A0 .%{ } ): =E2=80=A6
=C2=A0=C2=A0 val ( .%{ } <- ): =E2=80=A6

Nevertheless, contrarily to Bigarray, there is no implicit conversion for m= ultidimensional array,
in other words

=C2=A0=C2=A0=C2=A0 a .%{0,1}

will not work out of the box.

However, if needed, it is possible to use qualified indexing operators to c= ircumvent this difficulty:

=C2=A0 module D1 =3D struct let ( .%{} ) a k =3D a.{k} end
=C2=A0 module D2 =3D struct let ( .%{} ) a (k,l) =3D a.{k,l} end
=C2=A0 let x_ij =3D mat.D2.%{i, j}
=C2=A0 let x_0 =3D vector.D1.%{0}

See also the manual for more details: http://caml.inria.fr/pub/docs/manual-ocaml/extn.html#s%3Ai= ndex-operators .

=E2=88=92 octachron.

--
Caml-list mailing list.=C2=A0 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



--
=C3=A7<= /div>
--089e08224398b31409055e300589--