Browse thread
Request for complete pattern matching
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2005-11-23 (14:47) |
From: | Christophe Raffalli <christophe.raffalli@u...> |
Subject: | Re: [Caml-list] Request for complete pattern matching |
sejourne_kevin a écrit : > Christophe Raffalli a écrit : > >> - Lazy constructor and function can not be matched ... and this is >> ennoying >> >> I saw a post recently about lazy constructor and I can not write the >> camlp4 extension I want because of the second limitation ... >> >> It may be not clear what I mean by matching a function (looks impossible >> ;-). I mean something like >> >> pattern <= expr expr expr is a pattern >> >> and a function f is matched by >> >> p <= e1 ... eN iff f e1 ... eN is matched by p >> >> (I do not care about the final syntax ...) >> > > You want something like that ? > > let f = function > (x,y,z) when f x y z -> ... > | (x,y,z) when g x y z -> ... > | all_other_cases -> (static/compile_time)_error ... > No this is not a problem of test. I want to be able to write match e with (0 <= 0, g) -> g | (f, 0 <= 0) -> f | (f, g) -> fun x -> f x + g x which means the same as match e with (f, g) -> if f 0 = 0 then g else if g 0 = 0 then f else fun x -> f x + g x - The first problem is that removing this feature is a hard translation, and I would like the compiler to do it - The second problem is that I really need it to extend the pattern matching of ocaml using camlp4 Let us do a simple example (this is not what I am doing): type 'a lazy = unit -> 'a Lazy(e) := fun () -> e (defined as a camlp4 macro to be sure that e is not evaluated) and then "Lazy(p)" in a pattern means "p <= ()" (this should also be a camlp4 macro, but p <= () does not exist in the language) > Should be hard to eval f and g before execution... > > > > > > > Kévin. > > > > > > ___________________________________________________________________________ > Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! > Messenger Téléchargez cette version sur http://fr.messenger.yahoo.com > -- Christophe Raffalli Université de Savoie Batiment Le Chablais, bureau 21 73376 Le Bourget-du-Lac Cedex tél: (33) 4 79 75 81 03 fax: (33) 4 79 75 87 42 mail: Christophe.Raffalli@univ-savoie.fr www: http://www.lama.univ-savoie.fr/~RAFFALLI --------------------------------------------- IMPORTANT: this mail is signed using PGP/MIME At least Enigmail/Mozilla, mutt or evolution can check this signature. The public key is stored on www.keyserver.net ---------------------------------------------