From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 79D70BB9A for ; Thu, 27 Oct 2005 15:50:06 +0200 (CEST) Received: from ext.lri.fr (ext.lri.fr [129.175.15.4]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j9RDo6lZ004514 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 27 Oct 2005 15:50:06 +0200 Received: from localhost (localhost.localdomain [127.0.0.1]) by ext.lri.fr (Postfix) with ESMTP id 062D32024E8; Thu, 27 Oct 2005 15:50:06 +0200 (CEST) Received: from ext.lri.fr ([127.0.0.1]) by localhost (ext.lri.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 14697-08; Thu, 27 Oct 2005 15:50:05 +0200 (CEST) Received: from smtp.lri.fr (serveur3-5 [129.175.3.5]) by ext.lri.fr (Postfix) with ESMTP id EA2942024E4; Thu, 27 Oct 2005 15:50:05 +0200 (CEST) Received: from pc9-152 (pc9-152 [129.175.9.152]) by smtp.lri.fr (Postfix) with ESMTP id 8DCFDCED98; Thu, 27 Oct 2005 15:50:05 +0200 (CEST) Received: from filliatr by pc9-152 with local (Exim 3.36 #1 (Debian)) id 1EV88r-0001Kl-00; Thu, 27 Oct 2005 15:50:05 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <17248.56077.589928.491952@gargle.gargle.HOWL> Date: Thu, 27 Oct 2005 15:50:05 +0200 To: "Alexander A. Vlasov" Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Beginner's question. In-Reply-To: <1130419808.12902.13.camel@localhost.localdomain> References: <1130419808.12902.13.camel@localhost.localdomain> X-Mailer: VM 7.19 under Emacs 21.4.1 From: Jean-Christophe Filliatre X-Virus-Scanned: by amavisd-new at lri.fr X-Miltered: at concorde with ID 4360DB0E.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 beginner's:01 filliatre:01 filliatr:01 lri:01 ocaml:01 rec:01 defines:01 rec:01 ocaml:01 beginners:01 filliatre:01 lri:01 filliatr:01 writes:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Alexander A. Vlasov writes: > I'm making my first steps in OCaml and trying (just for expirience) to > implement a simple function which applies given function to all elements > of given list. > > But I can't do it using pattern matching -- following function doesn't > work > > let rec mapm func lst = function > | ( _, [] ) -> [] > | ( _, head::tail ) -> (func head) :: (mapm func tail) "function" defines a function over an anonymous argument which is immediatly filtered by the patterns. So your function mapm has actually 3 arguments, the 3rd of which is a pattern. I guess you intended to do some pattern matching on the two arguments of your function, which would be let rec mapm func list = match func, list with | _, [] -> [] | _, head :: tail -> func head :: mapm func tail but there is no need to do some pattern matching on the function, so let rec mapm func = function | [] -> [] | head : :tail -> func head :: mapm func tail would equally do, which is (regardless of the evaluation order) the code of List.map that you can find in the ocaml standard library. I you don't mind a comment: I think there is also a mailing list for ocaml beginners. Best regards, -- Jean-Christophe Filliātre (http://www.lri.fr/~filliatr)