caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Chris Hecker <checker@d6.com>
To: Alessandro Baretta <alex@baretta.com>, Ocaml <caml-list@inria.fr>
Subject: [Caml-list] views for strings (was: Pattern matching and strings)
Date: Wed, 02 Oct 2002 13:59:54 -0700	[thread overview]
Message-ID: <4.3.2.7.2.20021002125325.02941c80@mail.d6.com> (raw)
In-Reply-To: <3D9AFED2.2050400@baretta.com>


>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


  parent reply	other threads:[~2002-10-02 20:59 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-02 14:12 [Caml-list] Pattern matching and strings Alessandro Baretta
2002-10-02 15:02 ` Luc Maranget
2002-10-02 16:21   ` [Caml-list] Pattern matching and strings (and a mini-bug in Scanf) Alessandro Baretta
2002-10-02 17:15     ` Luc Maranget
2002-10-02 18:30       ` Alessandro Baretta
2002-10-02 18:32         ` Benjamin C. Pierce
2002-10-04 13:01       ` Florian Douetteau
2002-10-04  9:07     ` Pierre Weis
2002-10-04  9:31       ` Alessandro Baretta
2002-10-04 10:03         ` Pierre Weis
2002-10-04 10:23           ` Alessandro Baretta
2002-10-04 12:11             ` Remi VANICAT
2002-10-04 12:40               ` [Caml-list] Ocaml 3.06 Win2K OCAML/C link problem Ward Wheeler
2002-10-04 13:12               ` [Caml-list] Pattern matching and strings (and a mini-bug inScanf) Frederic van der Plancke
2002-10-04 19:31               ` [Caml-list] Pattern matching and strings (and a mini-bug in Scanf) Alessandro Baretta
2002-10-07  7:17                 ` Pierre Weis
2002-10-02 20:59 ` Chris Hecker [this message]
2002-10-02 23:09   ` [Caml-list] Re: views for strings (was: Pattern matching and strings) Alessandro Baretta
2002-10-03  8:31 ` [Caml-list] Pattern matching and strings Sven Luther
2002-10-04 12:00   ` Andreas Rossberg
2002-10-04 14:21     ` Kontra, Gergely
2002-10-04 15:14     ` Luc Maranget
2002-10-04 19:38       ` Alessandro Baretta
2002-10-05  6:34         ` [Caml-list] Camlp4 (Was: Pattern matching and strings) Daniel de Rauglaudre
2002-10-05 12:47           ` Sven LUTHER
2002-10-05 12:42             ` Daniel de Rauglaudre
2002-10-05 13:41               ` Michel Mauny
2002-10-05 13:47                 ` Daniel de Rauglaudre
2002-10-05 14:09                   ` Michel Mauny
2002-10-05 18:13                     ` Alessandro Baretta
2002-10-05 20:30                       ` [Caml-list] Future of Camlp4 Daniel de Rauglaudre
2002-10-04 19:13     ` [Caml-list] Pattern matching and strings Sven LUTHER

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4.3.2.7.2.20021002125325.02941c80@mail.d6.com \
    --to=checker@d6.com \
    --cc=alex@baretta.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).