* declaration of an infix operator in a .mli file
@ 1998-09-07 15:15 Laurent Chéno
1998-09-08 6:42 ` Pierre Weis
0 siblings, 1 reply; 2+ messages in thread
From: Laurent Chéno @ 1998-09-07 15:15 UTC (permalink / raw)
To: Caml list
Sorry : poor-english version at the end of this message.
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 ?
Et, au fait, pourquoi
let (prefix =?) x y = abs_float (x -. y) <. epsilon ;;
est-il incorrect ? (J'obtiens une Erreur de syntaxe.)
Cordialement, Laurent Chéno
----
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.
Another question : why is the following wrong ?
let (prefix =?) x y = abs_float (x -. y) <. epsilon ;;
(I obtain a Syntax error)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: declaration of an infix operator in a .mli file
1998-09-07 15:15 declaration of an infix operator in a .mli file Laurent Chéno
@ 1998-09-08 6:42 ` Pierre Weis
0 siblings, 0 replies; 2+ messages in thread
From: Pierre Weis @ 1998-09-08 6:42 UTC (permalink / raw)
To: Laurent Chéno; +Cc: caml-list
> 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/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1998-09-08 7:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-09-07 15:15 declaration of an infix operator in a .mli file Laurent Chéno
1998-09-08 6:42 ` Pierre Weis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox