Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
embedding ocaml into a windows app: need gcc?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-10-04 (01:38)
From: Jon Harrop <jonathandeanharrop@g...>
Subject: Re: [Caml-list] 'Compiler' module (was: embedding ocaml into a windows app: need gcc?)
On Friday 03 October 2008 22:34:15 Dawid Toton wrote:
> > I would like an OCaml support library that can compile and execute
> > similar to JaveScript engines, but we don't have that in any practical
> > form.
> I also need this and I'm thinking about something like this:
> module type Compiler =
> sig
>   val parse : Context.t -> string -> (Context.t * AST.t)
>   val get_type : Context.t -> AST.t -> Type.t;
>   val eval : Context.t -> AST.t -> Context.t * (Type.t *
> MarshalledValueOrSomething.t)
> end
> Is it really so hard to have it in OCaml?

The OCaml compiler's current design makes it extremely difficult but it is 
certainly entirely feasible (F# already does this, for example).

> I'm envy of Python's Compiler module.

Given that the sole objective of run-time compilation is performance and 
Python is vastly slower than OCaml, why are you the envy of Python's Compiler 
(to interpreted bytecode) module?

> It could solve some of my problems, in particular for my 'parallel-like'
> evaluation (
>98.html ). After some experimentation I know that I need type information
> during code transformation. I want to create a sort of interpreter.

I think (as Zheng implied) you want asynchronous workflows from F#. Note that 
these also handle cleanup of resources.

> That Compiler module would also enable me to have an editor with
> graphical representation of results intermixed with code (like
> Mathematica's notebook).

For a decent editor, you will need a lot more than that. I would certainly 
love to have such a thing but you also need access to the type checking phase 
to throwback type errors and having the data available in an efficient and 
accessible form would certainly be preferable.

I believe you can lex and parse OCaml using Camlp4 and then invoke the OCaml 
compiler with -dtypes to get the results of type checking. However, the 
latter is extremely inefficient. You really want the ability to restart the 
compiler from the end of the previous definition each time a file is edited.

> Where to look for suitable pieces of code? AFAIK camlp4 modules can't
> tell me type of anything. Should I start digging in OCaml compiler sources?

I'd start by reviewing asynchronous workflows.

Dr Jon Harrop, Flying Frog Consultancy Ltd.