* Patch "shared-vm" for ocaml-1.06
@ 1997-11-21 14:38 Fabrice Le Fessant
1997-11-21 18:26 ` type recursifs et abreviations cyclique and Co Emmanuel Engel
0 siblings, 1 reply; 4+ messages in thread
From: Fabrice Le Fessant @ 1997-11-21 14:38 UTC (permalink / raw)
To: caml-list
I updated my shared-vm patch for ocaml-1.06. It can be found in:
http://www-sor.inria.fr/~lefessan/src/shared-vm.tar.gz
both for ocaml-1.05 and ocaml-1.06.
It enables you to create new virtual machines extended with C
libraries and Ocaml bytecode files. As a result, executables using
these libraries are compiled faster (no -custom option needed) and are
really smaller. If you often use the "otherlibs/" libraries, you
should really use it.
Here is the README file for the patch (French and English):
--------------------------------------------------------------------------
Francais/French:
Releases 1.05 et 1.06
INTERET:
Ce patch permet de créer des exécutables OCAML utilisant des librairies
C et CAML sans avoir besoin d'utiliser l'option -custom. Cela évite de
recréer une machine virtuelle dans chaque exécutable. Le temps de
compilation est donc nettement réduit, et l'exécutable, qui ne contient plus
que le bytecode réellement propre à l'application, a une taille
largement inférieure et est plus portable.
INSTALLATION:
Placez-vous à la racine de la distribution ocaml-1.06. Le répertoire
doit donc contenir ./ocaml-1.06/
Appliquez le patch: patch < patch.ocaml-1.06
Puis recompilez: make (ou make world la première fois)
UTILISATION:
Ce patch permet de créer de nouvelles machines virtuelles, contenant à
la fois des librairies C et du bytecode préchargé.
Pour cela, il ajoute deux nouvelles options:
-make_vm : indique que l'on doit créer une nouvelle machine virtuelle
( le nom de la machine est précisé par l'option -o )
-use_vm <vm> : indique que le fichier généré utilisera la machine
virtuelle <vm> (précisez le chemin complet)
EXEMPLE:
# ocamlc -thread -make_vm -o ocamlthreadrun -cclib "-lunix -lthreads" \
unix.cma threads.cma
Cette commande génère deux fichiers:
- ocamlthreadrun : la nouvelle machine virtuelle, contenant en plus la
librairie Unix et la librairie Threads, ainsi que les bytecodes de
stdlib.cma, unix.cma et threads.cma
- ocamlthreadrun.cmc : ce fichier contient les informations nécéssaires
à la création des exécutables utilisant ocamlthreadrun comme machine
virtuelle
# mv ocamlthreadrun /usr/local/bin/
# mv ocamlthreadrun.cmc /usr/local/lib/ocaml-1.06
On déplace ces fichiers vers leur emplacement définitif.
ocamlthreadrun.cmc doit impérativement se trouver dans le chemin où le
compilateur recherchera les fichiers (librairie standard et répertoires
précisés par -I).
# ocamlc -thread -use_vm /usr/local/bin/ocamlthreadrun -o client client.ml
On compile le fichier client.ml et on crée l'exécutable client.
La machine virtuelle est référencée avec un chemin absolu qui est stocké
dans l'exécutable (#!/usr/local/bin/ocamlthreadrun en première ligne).
L'exécutable client ne contient que le bytecode de client.ml (stdlib.cma,
unix.cma et threads.cma sont dans la machine virtuelle). Si l'on
compile ocamlthreadrun sur différentes architectures, l'exécutable 'client'
sera donc utilisable par toutes ces machines.
# ./client
# ocamlthreadrun ./client
Pour exécuter notre fichier
--------------------------------------------------------------------------
Anglais/English(bad):
INTEREST:
This patch enable you to create OCAML programs using C and OCAML libraries
without using -custom option. Then, you will not create a new virtual machine
for each program. The compilation time is slightly decreased, and the
executable program, which only contains the own bytecode of your
application, is much smaller and more portable.
INSTALLATION:
Go in the root of ocaml-1.06 distribution. Your directory should contain
./ocaml-1.06/
Apply the patch: patch < patch.ocaml-1.06
Then compile again: make (or make world the first time)
UTILISATION:
This patch enable you to create new virtual machines, containing both
C libraries and OCAML pre-loaded bytecode.
For that, you have two new options:
-make_vm : To say you want to create a new virtual machine
( use -o option to choose the virtual machine name)
-use_vm <vm> : To say that the program you're linking will use
virtual machine <vm> (full absolute path)
EXAMPLE:
# ocamlc -thread -make_vm -o ocamlthreadrun -cclib "-lunix -lthreads" \
unix.cma threads.cma
This command will create two files:
- ocamlthreadrun : The new virtual machine, containing library Unix and
library Threads, and also stdlib.cma, unix.cma and threads.cma bytecodes.
- ocamlthreadrun.cmc : This file contains information needed to create
programs using ocamlthreadrun virtual machine.
# mv ocamlthreadrun /usr/local/bin/
# mv ocamlthreadrun.cmc /usr/local/lib/ocaml-1.06
We move the files to their right locations.
ocamlthreadrun.cmc must be in the path where ocamlc will search files
during linking (standard library and directories in -I option)
# ocamlc -thread -use_vm /usr/local/bin/ocamlthreadrun -o client client.ml
We compile client.ml and create executable file 'client'.
The absolute path of the virtual machine will appear in the executable
file (#!/usr/local/bin/ocamlthreadrun in first line).
The file 'client' only contains bytecode for client.ml (stdlib.cma,
unix.cma and threads.cma are already in the virtual machine ocamlthreadrun).
You can compile ocamlthreadrun on different machines, and use only one
version of 'client' on all of them.
# ./client
# ocamlthreadrun ./client
To execute file 'client'
---------------------------------------------------------
-- Fabrice LE FESSANT
Projet PARA, INRIA Rocquencourt
Fabrice.Le_Fessant@inria.fr
http://www-sor.inria.fr/~lefessan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: type recursifs et abreviations cyclique and Co
1997-11-21 14:38 Patch "shared-vm" for ocaml-1.06 Fabrice Le Fessant
@ 1997-11-21 18:26 ` Emmanuel Engel
0 siblings, 0 replies; 4+ messages in thread
From: Emmanuel Engel @ 1997-11-21 18:26 UTC (permalink / raw)
To: caml-list
D'une facon generale, je ne pense pas que le fait de ne pas pouvoir
ecrire de type cyclique enleve quelque chose. Une abreviation cyclique
definit en fait une instance recursive d'un type qui n'etait pas
necessairement recursif depuis le debut. Ainsi la definition de type
type x = x option
doit "moralement" etre equivalente au type
'a option as 'a
Le fait que caml interdise de tels (definitions de) types me semble une
bonne chose, les erreurs de typage en presence des types de la forme
"'a t as 'a" sont vraiement difficiles a trouver. De plus, il me
semble
que cela n'enleve rien. Par exemple la definition precedente est
equivalente (en tout cas a premiere vue) a
type x = None | Some of x;;
Si vraiement je veu utiliser les options, je peut toujours introduire
une constructeur bidon qui va masquer l'abreviation cyclique:
type x = X of x option;;
Le second mail porte exactement sur le meme probleme. Le principe est
que tout type recursifs ('a t as 'a) doit pouvoir etre redefini sous
une forme equivalente sans avoir besoin de "as". J'ai bien peur que
le second exemple soit plus difficile. Pour simplifier, j'ai mis la
module a plat, sans HALF. De plus include n'existe pas (suivant la
doc)
Voici le point de depart.
module type Pre =
sig
type ('a, 'b) h_label = | Lexicalized of 'a | Built of 'b
type ('a, 'b) h_unit = ('a, 'b) h_label option
type ('a, 'b, 'c) node =
{ mutable parent: ('a, 'b, 'c) node option;
mutable forest: ('a, 'b, 'c) node list;
mutable state: 'b;
mutable unit: ('a, 'c) h_unit
}
type p_state
and s_state
and p_label
and s_label
and p = (p_label, p_state, s) Half.node
and s = (s_label, s_state, p) Half.node
end;;
J'ai deux solutions. Le premiere est en fait de definir deux types
"node" differents, un par instance consideree. Cela donne plus ou moins
module type Pre =
sig
type ('a, 'b) h_label = | Lexicalized of 'a | Built of 'b
type ('a, 'b) h_unit = ('a, 'b) h_label option
type node_p =
{ mutable parent: node_p option;
mutable forest: node_p list;
mutable state: p_state;
mutable unit: (p_label, node_s) h_unit
}
and node_s =
{ mutable parent: node_s option;
mutable forest: node_s list;
mutable state: s_state;
mutable unit: (s_label, node_p) h_unit
}
and p_state
and s_state
and p_label
and s_label
type p = node_p
and s = node_s
end;;
Je suis d'accord c'est lourd, de plus les fonctions
val leq_cost : ('a, 'b, 'c) node -> ('a, 'b, 'c) node -> bool
val leq_p_cost : p -> p -> bool
val leq_s_cost : s -> s -> bool
val p_block : p -> unit
val s_block : s -> unit
doivent etre dupliquees. L'autre solution est le constructeur
bidon. Cela donne
module type Pre =
sig
type ('a, 'b) h_label = | Lexicalized of 'a | Built of 'b
type ('a, 'b) h_unit = ('a, 'b) h_label option
type ('a, 'b, 'c) node =
{ mutable parent: ('a, 'b, 'c) node option;
mutable forest: ('a, 'b, 'c) node list;
mutable state: 'b;
mutable unit: ('a, 'c) h_unit
}
and p_state
and s_state
and p_label
and s_label
and p = P of (p_label, p_state, s) node
and s = S of (s_label, s_state, p) node
end;;
Hope this help.
--
- Emmanuel Engel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: type recursifs et abreviations cyclique and Co
@ 1997-11-25 4:40 Jason Hickey
0 siblings, 0 replies; 4+ messages in thread
From: Jason Hickey @ 1997-11-25 4:40 UTC (permalink / raw)
To: caml-list
Cc: crary, hayden, Olivier Montanuy, Emmanuel Engel, Jerome Vouillon,
Francisco Valverde
Although my French is not what I would like, I gather that the feature
of general recursive types in OCaml has been drawn back because it is
prone to error. For instance, the type I originally proposed
type x = x option
is not allowed because types of that form are prone to error. The
solution would be to apply an explicit boxing:
type x = X of x option.
I would like to make an argument against this policy.
1. The interpretation of the general recursive type has a
well-defined type theoretic meaning. For instance, the type
type x = x option
is isomorphic to the natural numbers. The _type_theory_ does not
justify removing it from the language. Why not issue a warning rather
than forbidding the construction? For instance, the following code is
not forbidden:
let flag = (match List.length [] with 0 -> true)
even though constructions of this form are "prone to error,"
and generate warning messages.
2. The policy imposes a needless efficiency penalty on type
abstraction. For instance, suppose we have an abstract type
type 'a t
then we can't form the recursive type
type x = x t
without a boxing. Although the type
type x = X of x t
is equivalent, it requires threading a lot of superfluous X's through
the code, and ocaml will insert an extraneous boxing for each
occurrence of an item of type x in t. Consider an unlabeled
abstract binary tree:
type 'a t = ('a option) * ('a option) (* abstract *)
...
type node = X of node t
Every node is boxed, with a space penalty that is
linear in the number of nodes.
3. If the type system can be bypassed with an extraneous boxing,
type x = x t -----> type x = X of x t
then what is the point?
4. (Joke) All significant programs are "prone to error." Perhaps the
OCaml compiler should forbid them all!
I use this construction extensively in Nuprl (theorem proving)
and Ensemble (communications) applications; do I really need
to change my code?
Jason
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: type recursifs et abreviations cyclique and Co
@ 1997-11-25 11:30 Cuoq Pascal
0 siblings, 0 replies; 4+ messages in thread
From: Cuoq Pascal @ 1997-11-25 11:30 UTC (permalink / raw)
To: caml-list
Jason Hickey wrote :
> 2. The policy imposes a needless efficiency penalty on type
> abstraction.
> [...]
> ocaml will insert an extraneous boxing for each
> occurrence of an item of type x in t. Consider an unlabeled
> abstract binary tree:
>
> type 'a t = ('a option) * ('a option) (* abstract *)
> ...
> type node = X of node t
>
> Every node is boxed, with a space penalty that is
> linear in the number of nodes.
It seems to me that this is an argument for adding an optimization to
ocaml, not to change the typechecking algorithm :)
Pascal
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1997-11-26 9:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-11-21 14:38 Patch "shared-vm" for ocaml-1.06 Fabrice Le Fessant
1997-11-21 18:26 ` type recursifs et abreviations cyclique and Co Emmanuel Engel
1997-11-25 4:40 Jason Hickey
1997-11-25 11:30 Cuoq Pascal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).