Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] external & toplevel
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Virgile Prevosto <virgile.prevosto@m...>
Subject: Re: [Caml-list] external & toplevel
Hello Jonathan,

Le ven 27 jan 2006 05:56:31 CET, Jonathan Roewen a écrit:

> Is there a way to disallow external in the toplevel?
> 

I'm not too sure I really understand your question, but if you want to
prevent an user from writing an external definition in the toplevel, a
camlp4 "contraction" could do it:
------------------ wo_external.ml ----------------
(* use these directives for interactive use
#load "camlp4o.cma";;
#load "pa_extend.cmo";;
*)

open Pcaml;;
open Pa_o;;

DELETE_RULE 
str_item: "external"; LIDENT; ":"; ctyp; "="; LIST1 STRING 
END;;

DELETE_RULE 
str_item: "external"; "("; operator_rparen ; ":"; ctyp; "="; LIST1 STRING
END;;
-------------------------------------------
ocamlmktop -o ocaml_wo_external -pp "camlp4o pa_extend.cmo" \
  -I +camlp4 camlp4o.cma wo_external.ml 
./ocaml_wo_external
        Objective Caml version 3.09.1

        Camlp4 Parsing version 3.09.1

# external (+++) : int -> int -> int= "%addint";;
Toplevel input:
# external (+++) : int -> int -> int= "%addint";;
  ^^^^^^^^
Parse error: illegal begin of top_phrase
# external f: 'a -> 'a = "%identity";;
Toplevel input:
# external f: 'a -> 'a = "%identity";;
  ^^^^^^^^

-- 
E tutto per oggi, a la prossima volta
Virgile