caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: AUGER Cedric <sedrikov@gmail.com>
To: David Rajchenbach-Teller <David.Teller@ens-lyon.org>
Cc: Su Zhang <westlifezs@gmail.com>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] how can I express empty element?
Date: Mon, 09 Mar 2009 14:14:01 +0100	[thread overview]
Message-ID: <49B51619.9010306@lri.fr> (raw)
In-Reply-To: <1236603817.18569.4.camel@Blefuscu>

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


  reply	other threads:[~2009-03-09 13:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-09  3:59 Su Zhang
2009-03-09 13:03 ` [Caml-list] " David Rajchenbach-Teller
2009-03-09 13:14   ` AUGER Cedric [this message]
2009-03-09 16:07     ` Laurent Le Brun
2009-03-10  8:47     ` Grünewald Michaël

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=49B51619.9010306@lri.fr \
    --to=sedrikov@gmail.com \
    --cc=David.Teller@ens-lyon.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=westlifezs@gmail.com \
    /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).