caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* how can I express empty element?
@ 2009-03-09  3:59 Su Zhang
  2009-03-09 13:03 ` [Caml-list] " David Rajchenbach-Teller
  0 siblings, 1 reply; 5+ messages in thread
From: Su Zhang @ 2009-03-09  3:59 UTC (permalink / raw)
  To: caml-list

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

Hi all,

I have a question on ocaml, is there a way to write a empty element say a
which can make a::ax=ax ? I tried to find out in library, yet I didn't get
the right way out, and it doesn't work if I make a=[], so do you know
whether there is a technique can realize this function?  I've got stuck on
this point for a very long time.

thanks

-- 
Su Zhang
PHD Student
Computer Information and Science
Kansas State University

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

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

* Re: [Caml-list] how can I express empty element?
  2009-03-09  3:59 how can I express empty element? Su Zhang
@ 2009-03-09 13:03 ` David Rajchenbach-Teller
  2009-03-09 13:14   ` AUGER Cedric
  0 siblings, 1 reply; 5+ messages in thread
From: David Rajchenbach-Teller @ 2009-03-09 13:03 UTC (permalink / raw)
  To: Su Zhang; +Cc: caml-list

No, that's not possible. :: is an algebraic constructor, which means,
among other things, that it accepts no neutral element (well, except
when the list is infinite, but that's probably not what you're looking
for).

Cheers,
 David

On Sun, 2009-03-08 at 22:59 -0500, Su Zhang wrote:
> Hi all,
>  
> I have a question on ocaml, is there a way to write a empty element
> say a which can make a::ax=ax ? I tried to find out in library, yet I
> didn't get the right way out, and it doesn't work if I make a=[], so
> do you know whether there is a technique can realize this function?
> I've got stuck on this point for a very long time.
>  
> thanks
> 
> -- 
> Su Zhang
> PHD Student 
> Computer Information and Science
> Kansas State University 
> 
> _______________________________________________
> 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
-- 
David Teller-Rajchenbach
 Security of Distributed Systems
  http://www.univ-orleans.fr/lifo/Members/David.Teller
   « Ce matin Un crétin A tué un chercheur. » (air connu)
   Latest News of French Research: System being liquidated. Researchers angry.


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

* Re: [Caml-list] how can I express empty element?
  2009-03-09 13:03 ` [Caml-list] " David Rajchenbach-Teller
@ 2009-03-09 13:14   ` AUGER Cedric
  2009-03-09 16:07     ` Laurent Le Brun
  2009-03-10  8:47     ` Grünewald Michaël
  0 siblings, 2 replies; 5+ messages in thread
From: AUGER Cedric @ 2009-03-09 13:14 UTC (permalink / raw)
  To: David Rajchenbach-Teller; +Cc: Su Zhang, caml-list

David Rajchenbach-Teller wrote:
> No, that's not possible. :: is an algebraic constructor, which means,
> among other things, that it accepts no neutral element (well, except
> when the list is infinite, but that's probably not what you're looking
> for).
>   
And even if the list is infinite, I don't see any way to do it;
but you can always define:

let cons2 a l =
  match a with
    | Some x -> x::l
    | None -> l

and then use cons2 instead of :: the neutral element is then 'None', that is
cons2 None l = l.

And you can't do []::l excepted if l is a list of lists.
(And even so, []::l is not l!)

I don't see why one can want to have a "neutral" element in list, since 
it could mess a with pattern matching:

[] should be match as well with [] than with neutre::[]
> Cheers,
>  David
>
> On Sun, 2009-03-08 at 22:59 -0500, Su Zhang wrote:
>   
>> Hi all,
>>  
>> I have a question on ocaml, is there a way to write a empty element
>> say a which can make a::ax=ax ? I tried to find out in library, yet I
>> didn't get the right way out, and it doesn't work if I make a=[], so
>> do you know whether there is a technique can realize this function?
>> I've got stuck on this point for a very long time.
>>  
>> thanks
>>
>> -- 
>> Su Zhang
>> PHD Student 
>> Computer Information and Science
>> Kansas State University 
>>
>> _______________________________________________
>> 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] 5+ messages in thread

* Re: [Caml-list] how can I express empty element?
  2009-03-09 13:14   ` AUGER Cedric
@ 2009-03-09 16:07     ` Laurent Le Brun
  2009-03-10  8:47     ` Grünewald Michaël
  1 sibling, 0 replies; 5+ messages in thread
From: Laurent Le Brun @ 2009-03-09 16:07 UTC (permalink / raw)
  To: caml-list

On Mon, Mar 9, 2009 at 2:14 PM, AUGER Cedric <sedrikov@gmail.com> wrote:
> David Rajchenbach-Teller wrote:
>>
>> No, that's not possible. :: is an algebraic constructor, which means,
>> among other things, that it accepts no neutral element (well, except
>> when the list is infinite, but that's probably not what you're looking
>> for).
>
> And even if the list is infinite, I don't see any way to do it;

let rec li = 1 :: li

1 can be considered as a neutral element, since li = 1 :: li (of
course, the "=" function doesn't return, but the two lists have the
same elements).

-- 
  Laurent


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

* Re: [Caml-list] how can I express empty element?
  2009-03-09 13:14   ` AUGER Cedric
  2009-03-09 16:07     ` Laurent Le Brun
@ 2009-03-10  8:47     ` Grünewald Michaël
  1 sibling, 0 replies; 5+ messages in thread
From: Grünewald Michaël @ 2009-03-10  8:47 UTC (permalink / raw)
  To: AUGER Cedric; +Cc: David Rajchenbach-Teller, Su Zhang, caml-list


Le 9 mars 09 à 14:14, AUGER Cedric a écrit :

>
> David Rajchenbach-Teller wrote:
>> No, that's not possible. :: is an algebraic constructor, which means,
>> among other things, that it accepts no neutral element (well, except
>> when the list is infinite, but that's probably not what you're  
>> looking
>> for).
>>
> And even if the list is infinite, I don't see any way to do it;
> but you can always define:

If `l' is only infinite list with type `unit list', then `l' is a  
neutral element for `::' constructor, but only for `unit list'.

(Well, that is reminiscent of your favourite «consider a topological  
space with two points, one open and one closed»-example, but I did not  
find a better one!)
-- 
Cheers,
Michaël G.


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

end of thread, other threads:[~2009-03-10  8:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-09  3:59 how can I express empty element? Su Zhang
2009-03-09 13:03 ` [Caml-list] " David Rajchenbach-Teller
2009-03-09 13:14   ` AUGER Cedric
2009-03-09 16:07     ` Laurent Le Brun
2009-03-10  8:47     ` Grünewald Michaël

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