From: Reed Wilson <cedilla@gmail.com>
To: octachron <octa@polychoron.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Subtyping (or something like it)
Date: Fri, 17 Nov 2017 08:13:49 -0800 [thread overview]
Message-ID: <CALLFq5RoG5Obhndk_G++Uc92qdweLGcfVGSih73WZ+auGjzeJQ@mail.gmail.com> (raw)
In-Reply-To: <41144c60-9090-7159-c870-08ca5eb5c09e@polychoron.fr>
[-- Attachment #1: Type: text/plain, Size: 2073 bytes --]
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 ( .!{ } ) = get_1byte_int
let ( .@{ } ) = get_2byte_int
let ( .${ } ) = get_4byte_int
let ( .*{ } ) = 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 <octa@polychoron.fr> 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 operators:
>
> let ( .%{ } ) a k = a.{k}
> let ( .%{ } <- ) a k x = a.{k} <- x
>
> These operators can be used like standard indexing operators
>
> let x = a.%{ 0 } in
> a.%{ 1 } <- x
>
> and exported with
>
> val ( .%{ } ): …
> val ( .%{ } <- ): …
>
> 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 = struct let ( .%{} ) a k = a.{k} end
> module D2 = struct let ( .%{} ) a (k,l) = a.{k,l} end
> let x_ij = mat.D2.%{i, j}
> let x_0 = vector.D1.%{0}
>
> See also the manual for more details: http://caml.inria.fr/pub/docs/
> manual-ocaml/extn.html#s%3Aindex-operators .
>
> − 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
>
--
ç
[-- Attachment #2: Type: text/html, Size: 3117 bytes --]
next prev parent reply other threads:[~2017-11-17 16:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-16 21:46 Reed Wilson
2017-11-17 0:49 ` Yawar Amin
2017-11-17 2:05 ` Reed Wilson
2017-11-17 13:01 ` octachron
2017-11-17 16:13 ` Reed Wilson [this message]
2017-11-17 16:32 ` Leo White
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CALLFq5RoG5Obhndk_G++Uc92qdweLGcfVGSih73WZ+auGjzeJQ@mail.gmail.com \
--to=cedilla@gmail.com \
--cc=caml-list@inria.fr \
--cc=octa@polychoron.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox