From: Diego Olivier Fernandez Pons <dofp.ocaml@gmail.com>
To: caml-list <caml-list@inria.fr>
Subject: [Caml-list] Interpreting a language with (sparse) arrays explicitly indexed
Date: Tue, 18 Oct 2011 01:12:41 +0200 [thread overview]
Message-ID: <CAHqiZ-Lsy-jEb93VSPJzU2utf7GK8cU-RS66QBXeAR2GZcuHGA@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1467 bytes --]
Caml-list,
I have to write an interpreter for a language that has arrays explicitly
indexed by anything that can be sequential (list, range, set)
{string} airports = {"ATL", "JFK"};
range index = 1 .. 2;
tuple recordAirport { airport : string; id : int }
{recordAirport} otherAiports = { <"ATL", 12345>, <"JFK", 42>};
int myArray [airports][index] = [[1, 2], [3, 4]];
string myArray2 [a in recordAirports][i in index] = (i < a.id) ?
"unknown" : a.airport ;
int mySliceOfArray [a in recordAirports] = sum (i in index)
myArray[a.airport][i];
Usually the trick in interpreter implementation is to transform everything
back to "one-dimensional" objects
- simple types
- inductive constructions for lists
- curried functions
For instance in the book "Le langage Caml" the return type of the eval
function is
type value =
| Val_number of int
| Val_boolean of bool
| Val_pair of value * value
| Val_nil
| Val_cons of value * value
| Val_closure of closure
| Val_primitive of value -> value
and closure = { definition: (pattern * expression) list; mutable
environnement: environnement }
and environnement == (string * value) list
I don't see however how I am going to represent a type Val_Array given that
the indexes can be of arbitrary type and in arbitrary number.
I haven't found either how to transform the arrays into inductive types like
lists to avoid the issue.
Any suggestions ?
Diego Olivier
[-- Attachment #2: Type: text/html, Size: 2011 bytes --]
next reply other threads:[~2011-10-17 23:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-17 23:12 Diego Olivier Fernandez Pons [this message]
2011-10-18 8:07 ` Gabriel Scherer
2011-10-19 18:02 ` Diego Olivier Fernandez Pons
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=CAHqiZ-Lsy-jEb93VSPJzU2utf7GK8cU-RS66QBXeAR2GZcuHGA@mail.gmail.com \
--to=dofp.ocaml@gmail.com \
--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