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 JAA18878; Tue, 30 Jul 2002 09:27:55 +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 JAA18875 for ; Tue, 30 Jul 2002 09:27:54 +0200 (MET DST) Received: from laurelin.dementia.org ([208.167.88.73]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g6U7Rhj20351; Tue, 30 Jul 2002 09:27:43 +0200 (MET DST) Received: by laurelin.dementia.org (Postfix, from userid 1001) id BEB3670CF; Tue, 30 Jul 2002 03:34:56 -0400 (EDT) To: "Scott J." Cc: "Xavier Leroy" , "Caml-list" Subject: Re: [Caml-list] OCaml 3.05 released References: <20020729144527.A30919@pauillac.inria.fr> <000f01c2377c$36263060$2097fea9@janxp> From: John Prevost Date: 30 Jul 2002 03:34:56 -0400 (31.593 UMT) In-Reply-To: <000f01c2377c$36263060$2097fea9@janxp> Message-ID: <861y9lmzxb.fsf@laurelin.dementia.org> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >>>>> "sj" == Scott J writes: sj> What is meant by first first-class polymorphism? First class polymorphism in this case lets you define values with polymorphic types at levels other than the top level, like so: type foo = { test : 'a 'b . ('a -> 'b) -> 'a list -> 'b list } let a = { test = List.map } # a.test;; - : ('a -> 'b) -> 'a list -> 'b list = # a.test ((+) 1) [3; 5; 7];; - : int list = [4; 6; 8] # a.test ((^) "a") ["a"; "b"; "c"];; - : string list = ["aa"; "ab"; "ac"] For objects, this allows you to define a list type, complete with map method, as an object. For example: class ['a] clist x = object method map : 'b . ('a -> 'b) -> 'b list = fun f -> List.map f x end let a = new clist [1;2;3] let b = new clist ["a";"b";"c"] # a #map (fun x -> x + 1);; - : int list = [2; 3; 4] # b #map (fun x -> x ^ "-");; - : string list = ["a-"; "b-"; "c-"] (Note: this is a very uninteresting definition if a list class, but it should show you the kind of thing you can now do.) John. ------------------- 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