From: octachron <octa@polychoron.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Subtyping (or something like it)
Date: Fri, 17 Nov 2017 14:01:08 +0100 [thread overview]
Message-ID: <41144c60-9090-7159-c870-08ca5eb5c09e@polychoron.fr> (raw)
In-Reply-To: <CALLFq5QAJixXFyQQVT9sk59dLT3VXfMsEeHiE=U4CxmkNGpbnA@mail.gmail.com>
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.
next prev parent reply other threads:[~2017-11-17 14:02 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 [this message]
2017-11-17 16:13 ` Reed Wilson
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=41144c60-9090-7159-c870-08ca5eb5c09e@polychoron.fr \
--to=octa@polychoron.fr \
--cc=caml-list@inria.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