caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] pattern matching on integer intervals
@ 2012-01-21 18:14 Pierre Chopin
  2012-01-21 18:30 ` Till Varoquaux
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Pierre Chopin @ 2012-01-21 18:14 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 528 bytes --]

Hi,

I am trying to do pattern matching on unicode characters, represented by
integers. I would like to do something like that

 let f c =
 match c with
   0xff .. 0xfff -> foo

I know we can pattern match over char intervals but It doesn't be to be the
case for char intervals. Some I have two questions:
 Is there a better way of doing what I am doing and why is it possible to
pattern match over char intervals and not int intervals?

-- 
Pierre Chopin,
Chief Technology Officer and co-founder
punchup LLC
pierre@punchup.com

[-- Attachment #2: Type: text/html, Size: 670 bytes --]

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

* Re: [Caml-list] pattern matching on integer intervals
  2012-01-21 18:14 [Caml-list] pattern matching on integer intervals Pierre Chopin
@ 2012-01-21 18:30 ` Till Varoquaux
  2012-01-21 18:33 ` Gabriel Scherer
  2012-01-21 19:46 ` Edgar Friendly
  2 siblings, 0 replies; 4+ messages in thread
From: Till Varoquaux @ 2012-01-21 18:30 UTC (permalink / raw)
  To: Pierre Chopin; +Cc: caml-list

I remember wondering the same thing and the answer can be found in the
ocaml parser: char intervals are expanded at parse time to the the
full list of characters. This would blow up if you were to use ints,
int64 etc....

HTH,
Till

On Sat, Jan 21, 2012 at 1:14 PM, Pierre Chopin <pierre@punchup.com> wrote:
> Hi,
>
> I am trying to do pattern matching on unicode characters, represented by
> integers. I would like to do something like that
>
>  let f c =
>  match c with
>    0xff .. 0xfff -> foo
>
> I know we can pattern match over char intervals but It doesn't be to be the
> case for char intervals. Some I have two questions:
>  Is there a better way of doing what I am doing and why is it possible to
> pattern match over char intervals and not int intervals?
>
> --
> Pierre Chopin,
> Chief Technology Officer and co-founder
> punchup LLC
> pierre@punchup.com
>


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

* Re: [Caml-list] pattern matching on integer intervals
  2012-01-21 18:14 [Caml-list] pattern matching on integer intervals Pierre Chopin
  2012-01-21 18:30 ` Till Varoquaux
@ 2012-01-21 18:33 ` Gabriel Scherer
  2012-01-21 19:46 ` Edgar Friendly
  2 siblings, 0 replies; 4+ messages in thread
From: Gabriel Scherer @ 2012-01-21 18:33 UTC (permalink / raw)
  To: Pierre Chopin; +Cc: caml-list

I believe your best bet is the 'if .. then .. else' chain. You may
also use 'when' clauses in pattern matching, but those don't scale too
well and are best avoided if their are the only content of your
content: pattern matching are good for structural deconstruction and
environment binding, but can be confusing and useless when you are
using none of those aspects.

On Sat, Jan 21, 2012 at 7:14 PM, Pierre Chopin <pierre@punchup.com> wrote:
> Hi,
>
> I am trying to do pattern matching on unicode characters, represented by
> integers. I would like to do something like that
>
>  let f c =
>  match c with
>    0xff .. 0xfff -> foo
>
> I know we can pattern match over char intervals but It doesn't be to be the
> case for char intervals. Some I have two questions:
>  Is there a better way of doing what I am doing and why is it possible to
> pattern match over char intervals and not int intervals?
>
> --
> Pierre Chopin,
> Chief Technology Officer and co-founder
> punchup LLC
> pierre@punchup.com
>


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

* Re: [Caml-list] pattern matching on integer intervals
  2012-01-21 18:14 [Caml-list] pattern matching on integer intervals Pierre Chopin
  2012-01-21 18:30 ` Till Varoquaux
  2012-01-21 18:33 ` Gabriel Scherer
@ 2012-01-21 19:46 ` Edgar Friendly
  2 siblings, 0 replies; 4+ messages in thread
From: Edgar Friendly @ 2012-01-21 19:46 UTC (permalink / raw)
  To: caml-list

On 01/21/2012 01:14 PM, Pierre Chopin wrote:
> Hi,
>
> I am trying to do pattern matching on unicode characters, represented by
> integers. I would like to do something like that
>
>   let f c =
>   match c with
>     0xff .. 0xfff -> foo
>
> I know we can pattern match over char intervals but It doesn't be to be
> the case for char intervals. Some I have two questions:
>   Is there a better way of doing what I am doing and why is it possible
> to pattern match over char intervals and not int intervals?

The author of Camomile wrote IMap and ISet to efficiently store 
maps/sets over a large domain where large ranges are the same.  You may 
be able to use these DIET trees from camomile or from batteries to 
accomplish something along the lines of what you want.

E.


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

end of thread, other threads:[~2012-01-21 19:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-21 18:14 [Caml-list] pattern matching on integer intervals Pierre Chopin
2012-01-21 18:30 ` Till Varoquaux
2012-01-21 18:33 ` Gabriel Scherer
2012-01-21 19:46 ` Edgar Friendly

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