caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* a function for polymorphic and monomorphic objects
@ 2007-11-08  9:05 Keiko Nakata
  2007-11-08 10:48 ` [Caml-list] " Andrej Bauer
  2007-11-09  2:50 ` Jacques Garrigue
  0 siblings, 2 replies; 5+ messages in thread
From: Keiko Nakata @ 2007-11-08  9:05 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-11-09  2:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-08  9:05 a function for polymorphic and monomorphic objects Keiko Nakata
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

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).