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
--
Caml-list mailing list. Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs