Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* partial match in let
@ 2004-11-29 17:10 Christophe Raffalli
  2004-11-29 18:40 ` [Caml-list] " Dan Grossman
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Christophe Raffalli @ 2004-11-29 17:10 UTC (permalink / raw)
  To: caml-list

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


Wish: I had like a way to avoid the partial match warning in code like

let [x;y] = f (x) in foo

Because if foo is long writing

match f(x) with [x;y] -> foo | _ -> assert false

is really ennoying, especially if you have a long sequence of let.

I find usefull the partial match warning for match and function but not 
for let (if you write a let, I think you are aware that your matching 
will be partial for any data type with more than one constructor, you do 
not need a warning)

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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

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

* Re: [Caml-list] partial match in let
  2004-11-29 17:10 partial match in let Christophe Raffalli
@ 2004-11-29 18:40 ` Dan Grossman
  2004-11-29 18:45   ` Dan Grossman
  2004-11-29 18:42 ` Dan Grossman
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Dan Grossman @ 2004-11-29 18:40 UTC (permalink / raw)
  To: Christophe Raffalli; +Cc: caml-list


let g x = match f(x) with [x1;y1] -> (x,y) | assert false
let (x,y) = g x in foo

Christophe Raffalli wrote:
> 
> Wish: I had like a way to avoid the partial match warning in code like
> 
> let [x;y] = f (x) in foo
> 
> Because if foo is long writing
> 
> match f(x) with [x;y] -> foo | _ -> assert false
> 
> is really ennoying, especially if you have a long sequence of let.
> 
> I find usefull the partial match warning for match and function but not 
> for let (if you write a let, I think you are aware that your matching 
> will be partial for any data type with more than one constructor, you do 
> not need a warning)
> 


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

* Re: [Caml-list] partial match in let
  2004-11-29 17:10 partial match in let Christophe Raffalli
  2004-11-29 18:40 ` [Caml-list] " Dan Grossman
@ 2004-11-29 18:42 ` Dan Grossman
  2004-11-29 19:02 ` Robert W.
  2004-11-30 14:05 ` Luc Maranget
  3 siblings, 0 replies; 6+ messages in thread
From: Dan Grossman @ 2004-11-29 18:42 UTC (permalink / raw)
  To: Christophe Raffalli; +Cc: caml-list


let (x,y) = (match f(x) with [x1;y1] -> (x,y) | _ -> assert false) in foo

Christophe Raffalli wrote:

> 
> Wish: I had like a way to avoid the partial match warning in code like
> 
> let [x;y] = f (x) in foo
> 
> Because if foo is long writing
> 
> match f(x) with [x;y] -> foo | _ -> assert false
> 
> is really ennoying, especially if you have a long sequence of let.
> 
> I find usefull the partial match warning for match and function but not 
> for let (if you write a let, I think you are aware that your matching 
> will be partial for any data type with more than one constructor, you do 
> not need a warning)
> 


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

* Re: [Caml-list] partial match in let
  2004-11-29 18:40 ` [Caml-list] " Dan Grossman
@ 2004-11-29 18:45   ` Dan Grossman
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Grossman @ 2004-11-29 18:45 UTC (permalink / raw)
  To: Dan Grossman; +Cc: Christophe Raffalli, caml-list


Oops, a bit too hasty on the send (flaky mail reader):

let (x,y) = (match f(x) with [x1;y1] -> (x,y) | _ -> assert false) in foo

Dan Grossman wrote:

> 
> let g x = match f(x) with [x1;y1] -> (x,y) | assert false
> let (x,y) = g x in foo
> 
> Christophe Raffalli wrote:
> 
>>
>> Wish: I had like a way to avoid the partial match warning in code like
>>
>> let [x;y] = f (x) in foo
>>
>> Because if foo is long writing
>>
>> match f(x) with [x;y] -> foo | _ -> assert false
>>
>> is really ennoying, especially if you have a long sequence of let.
>>
>> I find usefull the partial match warning for match and function but 
>> not for let (if you write a let, I think you are aware that your 
>> matching will be partial for any data type with more than one 
>> constructor, you do not need a warning)
>>
> 
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs


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

* Re: [Caml-list] partial match in let
  2004-11-29 17:10 partial match in let Christophe Raffalli
  2004-11-29 18:40 ` [Caml-list] " Dan Grossman
  2004-11-29 18:42 ` Dan Grossman
@ 2004-11-29 19:02 ` Robert W.
  2004-11-30 14:05 ` Luc Maranget
  3 siblings, 0 replies; 6+ messages in thread
From: Robert W. @ 2004-11-29 19:02 UTC (permalink / raw)
  To: caml-list

Christophe Raffalli schrieb:

>
> Wish: I had like a way to avoid the partial match warning in code like
>
> let [x;y] = f (x) in foo
>
> Because if foo is long writing
>
> match f(x) with [x;y] -> foo | _ -> assert false
>

Wouldn't this be semantically equivalent to the constant function 
returning foo?
What I mean, instead of explicitly adding the wild card pattern, you can 
can substitute another one without. This would lead to an exhaustive 
pattern matching as well.

> is really ennoying, especially if you have a long sequence of let.
>
> I find usefull the partial match warning for match and function but 
> not for let (if you write a let, I think you are aware that your 
> matching will be partial for any data type with more than one 
> constructor, you do not need a warning)
>

I'm sure, there are formal problems with partial matching leading to 
serious serious headaches, but I'll need some time to think about.

-- 

	Robert...



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

* Re: [Caml-list] partial match in let
  2004-11-29 17:10 partial match in let Christophe Raffalli
                   ` (2 preceding siblings ...)
  2004-11-29 19:02 ` Robert W.
@ 2004-11-30 14:05 ` Luc Maranget
  3 siblings, 0 replies; 6+ messages in thread
From: Luc Maranget @ 2004-11-30 14:05 UTC (permalink / raw)
  To: Christophe Raffalli; +Cc: caml-list

> 
> Wish: I had like a way to avoid the partial match warning in code like
> 
> let [x;y] = f (x) in foo
> 
> Because if foo is long writing
> 
> match f(x) with [x;y] -> foo | _ -> assert false
> 
> is really ennoying, especially if you have a long sequence of let.
> 
> I find usefull the partial match warning for match and function but not 
> for let (if you write a let, I think you are aware that your matching 
> will be partial for any data type with more than one constructor, you do 
> not need a warning)
> 
> -- 
> Christophe Raffalli


I think the warning clearly is useful even in this situation of
a pattern in let.

In fact it can even be argued that 'let pat = exp in exp' should be legal
only when 'pat' provable cannot fail.
And the is camlp4 'revised syntax' approach, as far as I remember.


I also remark that your sentence
'I think you are aware that your matching 
will be partial for any data type with more than one constructor, you do 
not need a warning'
Does not apply to novices or in case of type alteration.


Besides a simple solution using a function has been given.


Cheers, 

-- 
Luc Maranget


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

end of thread, other threads:[~2004-11-30 14:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-29 17:10 partial match in let Christophe Raffalli
2004-11-29 18:40 ` [Caml-list] " Dan Grossman
2004-11-29 18:45   ` Dan Grossman
2004-11-29 18:42 ` Dan Grossman
2004-11-29 19:02 ` Robert W.
2004-11-30 14:05 ` Luc Maranget

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox