From: Pierre Weis <Pierre.Weis@inria.fr>
To: lcheno@club-internet.fr (Laurent Chéno)
Cc: caml-list@inria.fr
Subject: Re: declaration of an infix operator in a .mli file
Date: Tue, 8 Sep 1998 08:42:38 +0200 (MET DST) [thread overview]
Message-ID: <199809080642.IAA27315@pauillac.inria.fr> (raw)
In-Reply-To: <199809071512.RAA29206@front1.grolier.fr> from "Laurent Ch=?ISO-8859-1?Q?éno?=" at Sep 7, 98 05:15:07 pm
> 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 <?) = fun x y -> 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 -> 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 <? = fun x y -> 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 = 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 <?) = fun x y -> 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 -> 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 <? = fun x y -> 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 = x <. y +. epsilon
and prefix >? x y = y <. x +. epsilon;;
Pierre Weis
INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/
prev parent reply other threads:[~1998-09-08 7:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-09-07 15:15 Laurent Chéno
1998-09-08 6:42 ` Pierre Weis [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199809080642.IAA27315@pauillac.inria.fr \
--to=pierre.weis@inria.fr \
--cc=caml-list@inria.fr \
--cc=lcheno@club-internet.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox