Browse thread
[Caml-list] Breaking out of iterative loops
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Alessandro Baretta <alex@b...> |
| Subject: | Re: [Caml-list] Breaking out of iterative loops |
Markus Mottl wrote:
>
> I second this. Does anybody here really benefit from such cyclic
> structures?
I feel it necessary to cite prof. Jean-Jacques Levy's course
on programming languages at the Ecole Polytechnique:
(http://www.enseignement.polytechnique.fr/informatique/M2/lp/).
The following code illustrates how recursive data structures
might be used to build a caml interpreter.
type expression = string
type variable_name = string
type values =
Variable of variable_name
|
Const of int
|
Function of variable_name * expression * environment
and environment = (variable_name * values) list
The following is the internal representation the caml
interpreter would build of
"let rec fact x = if x = 0 then 1 else x * fact (x-1)"
let rec rho =
["fact" , Function ("x", "if x=0 then 1 else x * fact
(x-1)", rho)]
I hope this helps.
Alex
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners