From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA29053 for caml-redistribution; Tue, 8 Sep 1998 09:53:41 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id IAA09310 for ; Tue, 8 Sep 1998 08:42:41 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id IAA10434; Tue, 8 Sep 1998 08:42:38 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id IAA27315; Tue, 8 Sep 1998 08:42:38 +0200 (MET DST) From: Pierre Weis Message-Id: <199809080642.IAA27315@pauillac.inria.fr> Subject: Re: declaration of an infix operator in a .mli file To: lcheno@club-internet.fr (Laurent Ch=?ISO-8859-1?Q?éno?=) Date: Tue, 8 Sep 1998 08:42:38 +0200 (MET DST) Cc: caml-list@inria.fr In-Reply-To: <199809071512.RAA29206@front1.grolier.fr> from "Laurent Ch=?ISO-8859-1?Q?éno?=" at Sep 7, 98 05:15:07 pm X-Mailer: ELM [version 2.4 PL24 ME8] MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: weis > Dans foo.ml, j'ai les définitions suivantes de nouveaux opérateurs infixes : > > (***) > let epsilon = 1.0e-4 ;; > > let (prefix =?) = fun x y -> abs_float (x -. y) <. epsilon > and (prefix x <. y +. epsilon > and (prefix >?) = fun x y -> y <. x +. epsilon ;; > (***) > > Quel fichier foo.mli dois-je écrire pour les exporter ? value prefix =? : float -> float -> bool and prefix float -> bool and prefix >? : float -> float -> bool;; > Et, au fait, pourquoi > > let (prefix =?) x y = abs_float (x -. y) <. epsilon ;; > > est-il incorrect ? (J'obtiens une Erreur de syntaxe.) Il n'y a pas de bonne raison évidemment. Mais l'idée est que le mot-clé prefix suffit à introduire la version prefixe d'un opérateur infixe et que les parenthèses sont inutiles. On écrirait donc plutôt let prefix =? = fun x y -> abs_float (x -. y) <. epsilon and prefix x <. y +. epsilon and prefix >? = fun x y -> y <. x +. epsilon ;; et donc let prefix =? x y = abs_float (x -. y) <. epsilon and prefix ? x y = y <. x +. epsilon ;; ----- > I wrote this litte file foo.ml : > > (***) > let epsilon = 1.0e-4 ;; > > let (prefix =?) = fun x y -> abs_float (x -. y) <. epsilon > and (prefix x <. y +. epsilon > and (prefix >?) = fun x y -> y <. x +. epsilon ;; > (***) > > I do'nt know write the file foo.mli. value prefix =? : float -> float -> bool and prefix float -> bool and prefix >? : float -> float -> bool;; > Another question : why is the following wrong ? > > let (prefix =?) x y = abs_float (x -. y) <. epsilon ;; > > (I obtain a Syntax error) No really good reason. In fact the prefix keyword if used to introduce the prefix version of an infix operator. Hence the parens are useless and redundant. If you remove them then you can write let prefix =? = fun x y -> abs_float (x -. y) <. epsilon and prefix x <. y +. epsilon and prefix >? = fun x y -> y <. x +. epsilon;; and thus let prefix =? x y = abs_float (x -. y) <. epsilon and prefix ? x y = y <. x +. epsilon;; Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/