From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA25455; Wed, 2 Oct 2002 22:59:57 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA25298 for ; Wed, 2 Oct 2002 22:59:57 +0200 (MET DST) Received: from relay.pair.com (relay1.pair.com [209.68.1.20]) by concorde.inria.fr (8.11.1/8.11.1) with SMTP id g92Kxu515133 for ; Wed, 2 Oct 2002 22:59:56 +0200 (MET DST) Received: (qmail 60237 invoked from network); 2 Oct 2002 20:59:54 -0000 Received: from node-d8e9cca2-sfo-onnet.worldcom.com (HELO checkerlap.d6.com) (216.233.204.162) by relay1.pair.com with SMTP; 2 Oct 2002 20:59:54 -0000 X-pair-Authenticated: 216.233.204.162 Message-Id: <4.3.2.7.2.20021002125325.02941c80@mail.d6.com> X-Sender: checker@mail.d6.com X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Date: Wed, 02 Oct 2002 13:59:54 -0700 To: Alessandro Baretta , Ocaml From: Chris Hecker Subject: [Caml-list] views for strings (was: Pattern matching and strings) In-Reply-To: <3D9AFED2.2050400@baretta.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >take to make it work. Probably all it takes is some syntax-magic since the >above can be mapped onto the following: I'm wondering if you couldn't do something with views rather than hacking enhanced string matching into caml. http://citeseer.nj.nec.com/okasaki98view.html http://groups.google.com/groups?th=a59b2a184f8b8b40 I would much rather have a powerful general feature like Views where you could make these string matches somewhat cleaner, than have a hacked-in perl-esque regex system that isn't useful if you aren't doing string stuff. But, having said that, I'm not sure how you'd do your example with views. Even relaxing the "evaluate each view transform once and memoize" rule, I can't see how to specify the string prefix to the view transform: >let foo x = ... >let bar x = ... >... = function >| "foo" ^ rest -> foo rest >| "bar" ^ rest -> bar rest >| _ -> raise Unrecognized Using Okasaki's viewtype syntax, I think you'd want to do something like this: viewtype string = Prefix of string * string | NoPrefix match s with Prefix("foo",rest) -> foo rest | Prefix("bar",rest) -> bar rest | _ -> raise Unrecognized But the problem is that the parameter to the view transform is just the string s, so you can't get the "foo" to it to know whether it's a prefix. You could do viewtype string * string = Prefix | NoPrefix But then you'd have to specify the prefix in the match expression, which would be useless since there is more than one prefix you're looking for. You could do viewtype (string list) * string = Prefix of string * string and pre-specify all the prefixes, but that's totally stupid and useless. :) It seems like the view transformation only uses information in one direction, from the match expression to a constructor, but it can't get information from the available constructors to see if they're possible matches. There's no feedback. So, maybe views can't make this cleaner, or maybe I just don't know enough about them. Perhaps somebody who's thought about it more could say. Chris ------------------- 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