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
[Caml-list] OCaml as fancy calculator...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Max Skaller <skaller@m...>
Subject: Re: [Caml-list] OCaml as fancy calculator...
Oliver Bandel wrote:

> If I write some often-needed mathematical routines,
> so that it can be used with file-based OCaml-programs
> for compilation, how can I use such files (or the compiled
> byte-code or binaries) for interactive sessions with
> ocaml?
> Is this the first step to use the module system?

	Yes. First, create a file, say

and then compile it to bytecode:


Note that you have just created a module


Note the Capital letter onon the module name and the
lower case letter on the filename.

Now you can use it in the top level, in one or two steps.
First, you must say

	#load "my_routines.cmo"

Now you can say:

	My_routines.sin 1.2;;

and you'll get your routine 'sin' from module My_routines
called: thats the 'sin' in the file ''.
You can avoid typing the prefix 'My_routines' by saying

	open My_routines;;


	sin 1.2;;

but you should note that this will hide any other routine 'sin'
that's hanging around.

If you want to script a series of calculations in a file

you can say

	#use ""

Note that this is like a C #include: it compiles and executes as it
Whereas the #load is loading _already_ compiled code.

It's a good idea to run the top level 'ocaml' with 

	ledit ocaml

if you like keyboard editing. You'll need to download and build ledit
first. [Perhaps this will get built into the top level one day :-]

John (Max) Skaller, 
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
New generation programming language Felix
Literate Programming tool Interscript
Bug reports:  FAQ:
To unsubscribe, mail  Archives: