* [Caml-list] polymorphic methods in objects?
@ 2003-06-04 3:07 Lex Stein
2003-06-04 3:31 ` Nicolas Cannasse
0 siblings, 1 reply; 3+ messages in thread
From: Lex Stein @ 2003-06-04 3:07 UTC (permalink / raw)
To: caml-list
Hi,
Why can't objects have polymorphic methods ? I'm trying a compile and
ocamlc gets upset because I have a method with an unbound type in its
signature (see below for ocamlc error output).
Must methods be type paramaterized through some kind of a template
mechanism? This seems a bit limiting: the methods of an object would have
their type signature fixed across the lifetime of an object.
method dummy_init : 'a -> unit
method dump : out_channel -> unit
method init : unit -> unit
method join : string -> unit
method null : unit -> unit
method resolv : string -> hmap option
end
The method dummy_init has type 'a -> unit where 'a is unbound
make: *** [pastry.cmo] Error 2
Thanks,
Lex
---
Lex Stein http://www.eecs.harvard.edu/~stein/
Harvard Computer Science TEL: 617-495-5973
-------------------
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] polymorphic methods in objects?
2003-06-04 3:07 [Caml-list] polymorphic methods in objects? Lex Stein
@ 2003-06-04 3:31 ` Nicolas Cannasse
2003-06-04 17:30 ` Karl Zilles
0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Cannasse @ 2003-06-04 3:31 UTC (permalink / raw)
To: Lex Stein, caml-list
> Why can't objects have polymorphic methods ? I'm trying a compile and
> ocamlc gets upset because I have a method with an unbound type in its
> signature (see below for ocamlc error output).
>
> Must methods be type paramaterized through some kind of a template
> mechanism? This seems a bit limiting: the methods of an object would have
> their type signature fixed across the lifetime of an object.
>
> method dummy_init : 'a -> unit
> method dump : out_channel -> unit
> method init : unit -> unit
> method join : string -> unit
> method null : unit -> unit
> method resolv : string -> hmap option
> end
> The method dummy_init has type 'a -> unit where 'a is unbound
two ways of doing that :
first, having a parameterized object :
class ['a] my_object : object
method dummy_init : 'a -> unit
end
But perhaps here you really want that any value passed to your object is ok.
So you have to use a polymorphic method, which is not bound to the class
type :
class my_object : object
method dummy_init : 'a . 'a -> unit
end
This way, you cannot of course store the parameter into a field of my_object
this it is not polymorphic.
Nicolas Cannasse
-------------------
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] polymorphic methods in objects?
2003-06-04 3:31 ` Nicolas Cannasse
@ 2003-06-04 17:30 ` Karl Zilles
0 siblings, 0 replies; 3+ messages in thread
From: Karl Zilles @ 2003-06-04 17:30 UTC (permalink / raw)
To: Nicolas Cannasse; +Cc: Lex Stein, caml-list
Nicolas Cannasse wrote:
> two ways of doing that :
>
> first, having a parameterized object :
>
> class ['a] my_object : object
> method dummy_init : 'a -> unit
> end
>
> But perhaps here you really want that any value passed to your object is ok.
> So you have to use a polymorphic method, which is not bound to the class
> type :
>
> class my_object : object
> method dummy_init : 'a . 'a -> unit
> end
>
> This way, you cannot of course store the parameter into a field of my_object
> this it is not polymorphic.
The stuff Nicolas mentions is covered in sections 3.9 and 3.10 of the
current manual. You should probably read these sections, because use of
polymorphic methods can sometimes require type constraints.
http://caml.inria.fr/ocaml/htmlman/manual005.html#ss:parameterized-classes
http://caml.inria.fr/ocaml/htmlman/manual005.html#ss:polymorphic-methods
-------------------
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-06-04 17:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-04 3:07 [Caml-list] polymorphic methods in objects? Lex Stein
2003-06-04 3:31 ` Nicolas Cannasse
2003-06-04 17:30 ` Karl Zilles
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox