English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Snd question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-08-15 (22:40)
From: Matt Gushee <mgushee@h...>
Subject: Re: [Caml-list] Snd question
Anu Engineer wrote:

 > Please forgive me if my question is very naïve, I am very new to 
Ocaml. I was

 > wondering why snd returns an  error when I use it with more than 2 
elements, why

 > not return the rest of the list when I apply to something larger than 
a pair ?

Your question shows your misunderstanding: snd operates on tuples, not 
lists. If it did operate on lists the length wouldn't matter, because 
length doesn't affect the type of a list. I.e.

     [ 1; 2; 3; ... n ]

is of type 'int list' whether it has 4 elements or 40,000,000. Whereas 
tuples have the same type if and only if they have the same number of 
members, and all members have the same types. E.g:

     VALUE        TYPE
     (1, 2)         int * int
     (1, 2, 4)        int * int * int
     (57, false)            int * bool
     ('x', "buzz")       char * string

There is no such thing as a tuple with an arbitrary number of members, 
thus no function that can operate on one.

I hope that clarifies things a bit. By the way, this sort of question is 
probably best asked on the beginner's list (you'll see the address at 
the bottom of this message).

Matt Gushee
Englewood, CO, USA