From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id EAA16769; Thu, 20 Nov 2003 04:32:19 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA16290 for ; Thu, 20 Nov 2003 04:32:18 +0100 (MET) Received: from chase3000.com (mercury.chase3000.com [12.36.212.25]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hAK3WF106377 for ; Thu, 20 Nov 2003 04:32:17 +0100 (MET) Received: from skeeter.chase3000.com ([172.16.11.212]) by chase3000.com (chase3000.com [12.36.212.25]) (MDaemon.PRO.v6.8.5.R) with ESMTP id 65-md50000000220.tmp for ; Wed, 19 Nov 2003 20:31:44 -0700 Message-Id: <5.2.0.9.0.20031119204912.00a9fb28@127.0.0.1> X-Sender: mail.chase3000.com:sketerpot@127.0.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.2.0.9 Date: Wed, 19 Nov 2003 20:54:08 -0700 To: caml-list@inria.fr From: Peter Scott Subject: [Caml-list] Recursive apply function Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Spam-Processed: chase3000.com, Wed, 19 Nov 2003 20:31:44 -0700 (not processed: message from valid local sender) X-MDRemoteIP: 172.16.11.212 X-Return-Path: sketerpot@chase3000.com X-MDaemon-Deliver-To: caml-list@inria.fr X-Loop: caml-list@inria.fr X-Spam: no; 0.00; imitate:01 recursively:01 ocaml:01 lisp:01 int:01 rec:01 match:02 recursive:03 types:03 let:04 let:04 arg:06 arg:06 args:06 args:06 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I'm having an interesting disagreement with ocaml about types. I'm trying to make a function to imitate the lisp apply function. That is, I want to make a function which will apply another function to a list. I came up with this code: let rec apply f args = match args with arg :: rest -> apply (f arg) rest | [] -> f;; let add x y = x + y;; let x = apply add [2; 3];; print_int x;; As you can see, the idea is to go recursively applying the function to the first element of the list. Unfortunately, I get this message when run: "This expression has type 'a but is here used with type 'b -> 'a", referring to the "(f arg)" part. Is there a way around this? -Peter ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners