[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | AUGER Cedric <sedrikov@g...> |
| Subject: | Re: [Caml-list] how can I express empty element? |
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
>>