caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] "map"-ing parameterized class types
@ 2015-10-19 16:58 Spiros Eliopoulos
  2015-10-19 18:14 ` Jeremy Yallop
  0 siblings, 1 reply; 7+ messages in thread
From: Spiros Eliopoulos @ 2015-10-19 16:58 UTC (permalink / raw)
  To: OCaml

[-- Attachment #1: Type: text/plain, Size: 921 bytes --]

Hey List,

I'm trying to create a "container" class[0] that can store a value of type
'a, and transform that value to another value of type 'b. I'm trying to do
this by including a "map" method in the container that applies a function
to the value and returns a new instance of container with the transformed
value. Despite the annotations, the types aren't working out as I expected:

  class ['a] container (v:'a) = object
    method map (f:'a -> 'b) : 'b container = new container (f v)
  end;;
  (* class ['a] container : 'a -> object method map : ('a -> 'a) -> 'a
container end  *)

I gather I'm either doing something wrong, or it's not possible. I suppose
my question, which one is it? and if I'm doing something wrong, some
guidance would be appreciated. Thanks!

-Spiros E.

[0]: Note that this is a minimal, contrived example of my actual problem.
The actual problem came up while writing js_of_ocaml bindings.

[-- Attachment #2: Type: text/html, Size: 1192 bytes --]

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

end of thread, other threads:[~2015-11-26 23:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-19 16:58 [Caml-list] "map"-ing parameterized class types Spiros Eliopoulos
2015-10-19 18:14 ` Jeremy Yallop
2015-10-19 20:15   ` Spiros Eliopoulos
2015-10-20 11:57     ` Mikhail Mandrykin
2015-11-26 23:25       ` Glen Mével
2015-10-22 15:04     ` Oleg
2015-10-23  6:48       ` 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).