caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] égalité physique (==) avec Pervasives.(+)
@ 2003-01-06 17:58 Diego Olivier Fernandez Pons
  2003-01-07 14:41 ` Christophe Raffalli
  0 siblings, 1 reply; 4+ messages in thread
From: Diego Olivier Fernandez Pons @ 2003-01-06 17:58 UTC (permalink / raw)
  To: caml-list

    Bonjour,

Je suis en train de préparer le système de description de contraintes
pour les algorithmes de descente sur les polyhèdres (i.e. simplexe et
variantes locales) que l'on utilise dans les approximations de
problèmes NP-difficiles

J'essaie d'encapsuler le type ['a] dans un type ['a expr]

type 'a expr =
  | Constante of 'a
  | Variable of int
  | Operateur of 'a expr * 'a expr * ('a -> 'a -> 'a)
  | Application of 'a expr * ('a -> 'a)

let inj = function x -> Constante x

let inj1 f = function expression ->
  match expression with
   | Constante v -> Constante f v
   | Variable _ | Operateur _ | Application _ ->
      Application (expression, f)

let inj2 f = fun x y ->
  match (x, y) with
    | (Constante s, Constante t) -> Constante (f s t)
    | _ -> Operateur (x, y, f)

val inj  : 'a -> 'a expr
val inj1 : ('a -> 'a) -> ('a expr -> 'a expr)
val inj2 : ('a -> 'a -> 'a) -> ('a expr -> 'a expr -> 'a expr)
val eval : 'a env -> 'a expr -> 'a

Maintenant je veux traverser la syntaxe abstaite et optimiser le
traitement des opérateurs les plus simples (*, +, /, ...) et pour les
reconnaître j'utilise l'égalité physique (==)

Seulement, les opérateurs Pervasive.qqch ne semblent pas se comporter
comme les fonctions définies par l'utilisateur :

let f = function x -> x + 1
let a = (1, f)
let (_, g) = a

f == g
- : bool = true

let a = (1, (+))
let (_, g) = a

(+) == g
- : bool = false

let a = (1, Pervasives.(+))
let (_, g) = a

Pervasives.(+) == g
- : bool = false


Pourquoi ce comportement ? Comment contourner le problème ?

        Diego Olivier

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-01-08 17:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-06 17:58 [Caml-list] égalité physique (==) avec Pervasives.(+) Diego Olivier Fernandez Pons
2003-01-07 14:41 ` Christophe Raffalli
2003-01-08 16:51   ` Florian Hars
2003-01-08 17:34   ` Diego Olivier Fernandez Pons

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).