Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Problem with classes or i need help
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] Problem with classes or i need help
> class virtual figure () =
>   object
>     method virtual to_string: string
>   end
[...]
> class screen () =
>   object
>     val mutable figures = []
>     method add_figure f =
>       figures <- (f#to_string ) :: figures
>   end
[...]
> The method add_figure has type < to_string : 'a; .. > -> unit where ..
> is unbound
> 
> I understand the problem, but i don't know solution, help, please.

Are you sure you understood ?-)
There's nothing in your program to tell the compiler that the argument
to add_figure is supposed to be a figure.

    method add_figure (f : figure) =
      figures <- f#to_string :: figures

Or, if you want to avoid coercions when calling #add_figure,

    method add_figure : 'a. (#figure as 'a) -> unit = fun f ->
      figures <- f#to_string :: figures

Jacques Garrigue
-------------------
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