From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p9HNCenr013209 for ; Tue, 18 Oct 2011 01:12:42 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjwBAMu1nE5KfVI0kGdsb2JhbABDoR4BhzAIIgEBAQEJCQ0HFAQhggcCExkBGx4DEgkHXQERAQUBIjWeXoJYCotRgmCFUz2IbgIFCod+BJN6jSg9g3E X-IronPort-AV: E=Sophos;i="4.69,362,1315173600"; d="scan'208";a="124502050" Received: from mail-ww0-f52.google.com ([74.125.82.52]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 18 Oct 2011 01:12:41 +0200 Received: by wwf25 with SMTP id 25so5274wwf.9 for ; Mon, 17 Oct 2011 16:12:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=lQ/iIqZvlUnE4tW86EBpXUfHEIc56EktDFCMBYXkNUU=; b=khWZYFpklsL7U1Cm37O/foDGmAjaDslL+DEagt46L/54D6r3bVwPAaBQWbzdpOCMs8 v9YOF+PG5I4z4ZHNXbuPh3R8XXFz6StzinSOX3zj0MXfGXLwMQUQYNid3vqjW37cBJy8 xSRsH9Br2o5csTAr+VUsmg1BG7wrZp+gqbi8w= MIME-Version: 1.0 Received: by 10.216.164.74 with SMTP id b52mr4360266wel.94.1318893161569; Mon, 17 Oct 2011 16:12:41 -0700 (PDT) Received: by 10.216.73.131 with HTTP; Mon, 17 Oct 2011 16:12:41 -0700 (PDT) Date: Tue, 18 Oct 2011 01:12:41 +0200 Message-ID: From: Diego Olivier Fernandez Pons To: caml-list Content-Type: multipart/alternative; boundary=0016e6498454645e9804af86beb3 Subject: [Caml-list] Interpreting a language with (sparse) arrays explicitly indexed --0016e6498454645e9804af86beb3 Content-Type: text/plain; charset=ISO-8859-1 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 --0016e6498454645e9804af86beb3 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable =A0 =A0 =A0Caml-list,

I have to write an interpreter for= a language that has arrays explicitly indexed by anything that can be sequ= ential (list, range, set)

=A0 =A0 {string} airport= s =3D {"ATL", "JFK"};
=A0 =A0 range index =3D 1 .. 2;
=A0 =A0 tuple recordAirport = { airport : string; id : int }
=A0 =A0 {recordAirport} otherAipor= ts =3D { <"ATL", 12345>, <"JFK", 42>};

=A0 =A0 int myArray [airports][index] =3D [[1, 2], [3, 4]];
= =A0 =A0 string myArray2 [a in recordAirports][i in index] =3D (i < a.id) ? "unknown" : a.airport ;
= =A0 =A0 int mySliceOfArray [a in recordAirports] =A0=3D sum (i in index) my= Array[a.airport][i];

Usually the trick in interpreter implementation is to t= ransform everything back to "one-dimensional" objects
-= simple types
- inductive constructions for lists
- cur= ried functions

For instance in the book "Le langage Caml" th= e return type of the eval function is

type va= lue =3D
=A0 =A0| Val_number of int
=A0 =A0| Val_boolean= of bool
=A0 =A0| Val_pair of value * value
=A0 =A0| Val_nil
=A0 =A0| Val_cons of value * value
=A0 =A0| Val_closure of clos= ure
=A0 =A0| Val_primitive of value -> value
and clo= sure =3D=A0{ definition: (pattern * expression) list;=A0mutable environneme= nt: environnement }
and environnement =3D=3D (string * value) list

I don't see however how I am going to represent a type Val_Arra= y given that the indexes can be of arbitrary type and in arbitrary number.<= /div>
I haven't found either how to transform the arrays into inductive = types like lists to avoid the issue.

Any suggestio= ns ?

=A0 =A0 =A0 =A0 Diego Olivier
--0016e6498454645e9804af86beb3--