From: John Prevost <j.prevost@cs.cmu.edu>
To: "Scott J." <jscott@planetinternet.be>
Cc: "Xavier Leroy" <xavier.leroy@inria.fr>, "Caml-list" <caml-list@inria.fr>
Subject: Re: [Caml-list] OCaml 3.05 released
Date: 30 Jul 2002 03:34:56 -0400 (31.593 UMT) [thread overview]
Message-ID: <861y9lmzxb.fsf@laurelin.dementia.org> (raw)
In-Reply-To: <000f01c2377c$36263060$2097fea9@janxp>
>>>>> "sj" == Scott J <jscott@planetinternet.be> 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 = <fun>
# 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
next prev parent reply other threads:[~2002-07-30 7:27 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-29 12:45 Xavier Leroy
2002-07-29 14:36 ` Nicolas Cannasse
2002-07-30 0:46 ` Shawn Wagner
2002-07-30 3:50 ` Scott J.
2002-07-30 7:34 ` John Prevost [this message]
2002-07-30 7:46 ` [Caml-list] Serious typechecking error involving new polymorphism (crash) John Prevost
2002-07-30 7:58 ` Xavier Leroy
2002-07-30 8:22 ` John Prevost
2002-07-30 8:47 ` Xavier Leroy
2002-07-30 8:37 ` Sven LUTHER
2002-07-30 14:11 ` [Caml-list] bug-fix branches Xavier Leroy
2002-07-30 16:15 ` Sven LUTHER
2002-08-01 9:37 ` [Caml-list] 3.05 and future 3.06 binary compatibility ? root
2002-08-01 12:09 ` [Caml-list] " Xavier Leroy
2002-08-01 15:56 ` Sven LUTHER
2002-08-08 8:37 ` Sven LUTHER
2002-08-09 12:25 ` Xavier Leroy
2002-08-09 13:16 ` Sven LUTHER
2002-07-30 7:51 ` [Caml-list] OCaml 3.05 released Dmitry Bely
2002-07-30 15:01 ` Scott J.
2002-07-30 15:11 ` Dmitry Bely
2002-08-02 5:31 ` Jacques Garrigue
2002-08-02 11:15 ` Tim Freeman
2002-07-30 7:48 ` [Caml-list] Record with one non mutable filed Christophe Raffalli
2002-07-30 11:49 ` [Caml-list] OCaml 3.05 released Yaron M. Minsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=861y9lmzxb.fsf@laurelin.dementia.org \
--to=j.prevost@cs.cmu.edu \
--cc=caml-list@inria.fr \
--cc=jscott@planetinternet.be \
--cc=xavier.leroy@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).