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 UAA29704; Mon, 30 Jul 2001 20:47:39 +0200 (MET DST) 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 UAA29281 for ; Mon, 30 Jul 2001 20:47:39 +0200 (MET DST) Received: from smtp1.cswv.com (smtp1.cswv.com [4.17.129.17]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f6UIlcb26436 for ; Mon, 30 Jul 2001 20:47:38 +0200 (MET DST) Received: from smtp1.cswv.com ([4.17.129.17]) by smtp1.cswv.com with Microsoft SMTPSVC(5.5.1877.197.19); Mon, 30 Jul 2001 14:47:51 -0400 Received: FROM exchange1.cswv.com BY smtp1.cswv.com ; Mon Jul 30 14:47:50 2001 -0400 Received: by exchange1.cswv.com with Internet Mail Service (5.5.2653.19) id ; Mon, 30 Jul 2001 14:51:11 -0400 Message-ID: From: "Krishnaswami, Neel" To: "'caml-list@inria.fr'" Subject: [Caml-list] Why can't I use constructors as functions? Date: Mon, 30 Jul 2001 14:51:07 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, I'm curious as to the reason why I can't use a datatype constructor as a function. Eg, in SML I can write a function like this: datatype peano = Zero | Succ of peano fun fold succ zero n = case n of Zero => zero | (Succ n') => succ (fold n') fun add a b = fold Succ a b (* Use the Succ constructor as a funtion *) If I try something similar in Caml, type peano = Zero | Succ of peano let rec fold succ zero n = match n with | Zero -> zero | Succ(n') -> succ (fold succ zero n') I can't write an add function like I can in SML: # let add a b = fold (Succ) a b;; Characters 20-24: The constructor Succ expects 1 argument(s), but is here applied to 0 argument(s) Instead I need to wrap it in a function: # let add a b = fold (fun x -> Succ x) a b val add : peano -> peano -> peano = Why was this design choice made? -- Neel Krishnaswami neelk@cswcasa.com ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr