Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Again on pattern matching and strings
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alessandro Baretta <alex@b...>
Subject: Re: [Caml-list] Again on pattern matching and strings


Stefano Zacchiroli wrote:
> On Thu, Oct 24, 2002 at 01:47:33AM +0200, Alessandro Baretta wrote:
> 
>>| Some ( "\027(U\001\000\005" ) -> ...
>>| Some ( "\027@" ) -> ...
>>| Some ( "\012" ) -> ...
> 
> 
> What about:
> 
>   | Some m when m = printer_set_unit -> ...
>   | Some m when m = printer-reset -> ...
>   | Some m when m = printer_formfeed -> ...
>   ...
>   | Some (_) -> assert false
>   | None -> ()
> 
> It isn't so bad ...

Eh, no! This is really unacceptable as a general solution. 
Of course, I could have coded my function this way, but this 
technique is not scalable, especially from the perspective 
of computational efficiency. Your code is compiled as a 
sequence of comparisons on a strings. Hence, the matched 
string is scanned once for every pattern. With constant 
patterns, on the other hand, the compiler should scan the 
string only once and jump to appropriate code. This is more 
compact, but not necessarily more efficient, as Jacques 
pointed out a while ago.
( http://caml.inria.fr/archives/200101/msg00111.html )

> Anyway from a more general point of view I'm also interested in seeing
> "aliasing" or constant definition in the compiler, it is of general
> interest, not only in pattern matching.

To my great surprise, I'm unable to think of an example 
relating to anything other than pattern matching.

Alex

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