From: Keiko Nakata <keiko@kurims.kyoto-u.ac.jp>
To: caml-list@inria.fr
Subject: a function for polymorphic and monomorphic objects
Date: Thu, 08 Nov 2007 18:05:32 +0900 (JST) [thread overview]
Message-ID: <20071108.180532.68538077.keiko@kurims.kyoto-u.ac.jp> (raw)
Hello.
Can I define a function taking as argument
an object with a method, say, "map" whose type is instantiatable to
(int -> int) -> int list?
I have two object;
one with a polymorphic map, the other with a monomorphic map.
let p = object
method map : 'a.(int -> 'a) -> 'a list = fun f -> List.map f [1;2;3]
end;;
let q = object
method map : (int -> int) -> int list = fun f -> List.map f [1;2;3]
end;;
I want to define a function like double below,
which is applicable to both p and q.
let double o = o#map (fun x -> x*2);;
The only workaround I came up with is
let double2 f = f (fun x -> x*2);;
double2 p#map;;
double2 q#map;;
Yet this is not very nice....
With best regards,
Keiko
next reply other threads:[~2007-11-08 9:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-08 9:05 Keiko Nakata [this message]
2007-11-08 10:48 ` [Caml-list] " Andrej Bauer
2007-11-08 12:09 ` Keiko Nakata
2007-11-09 1:35 ` Peng Zang
2007-11-09 2:50 ` Jacques Garrigue
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=20071108.180532.68538077.keiko@kurims.kyoto-u.ac.jp \
--to=keiko@kurims.kyoto-u.ac.jp \
--cc=caml-list@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