List Info

Thread: "ocaml_beginners"::[] polymorphic methods (and I've read the same named section of the manual :-)




"ocaml_beginners"::[] polymorphic methods (and I've read the same named section of the manual :-)
user name
2006-07-27 17:44:30
On Thu, 27 Jul 2006, vincent.aravantinos wrote:

> Even if I only define the class type :
>
> class type ['a] myclass =
>  object val the_list : 'a list method map : 'a ->
'b myclass end;;
>
> then it automatically turns it into :
>
> class type ['a] myclass =
>  object val the_list : 'a list method map : 'a ->
'a myclass end
>
> ????

It's not specific to classes:

# let rec f x y = if false then f y x;;
val f : 'a -> 'a -> unit = <fun>

could be:

val f : 'a -> 'b -> unit = <fun>


Martin

--
Martin Jambon, PhD
http://martin.jambon.fre
e.fr


Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http:/
/groups.yahoo.com/group/ocaml_beginners/

<*> To unsubscribe from this group, send an email to:
    ocaml_beginners-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 



"ocaml_beginners"::[] polymorphic methods (and I've read the same named section of the manual :-)
user name
2006-07-28 07:23:09
--- In ocaml_beginners@yahoogroups.com, Martin Jambon 
<martin_jambon...> wrote:
>
> On Thu, 27 Jul 2006, vincent.aravantinos wrote:
> 
> > Even if I only define the class type :
> >
> > class type ['a] myclass =
> >  object val the_list : 'a list method map : 'a
-> 'b myclass end;;
> >
> > then it automatically turns it into :
> >
> > class type ['a] myclass =
> >  object val the_list : 'a list method map : 'a
-> 'a myclass end
> >
> > ????
> 
> It's not specific to classes:
> 
> # let rec f x y = if false then f y x;;
> val f : 'a -> 'a -> unit = <fun>
> 
> could be:
> 
> val f : 'a -> 'b -> unit = <fun>

Are you sure this is the same problem ?
Because to know the real type there the compiler must do
some 
semantics checks to know that f y x will never be called. It
seems to 
me that for classes, no such checks are needed.

I read what R.Jones advised me :
http://cam
l.inria.fr/pub/ml-archives/caml-
list/2005/02/a67b1a509263be01705305f36d64c39c.en.html [1]
it is kind of same problem that mine : in [1] they have two
recursive 
classes, and they solve the pb by avoiding the recursion
defining a 
class type. The pb is that in my case, there is only one
class, which 
is kind of "auto-recursive"...

In a more general way, I feel that if a class is polymorphic
(say 'a 
myclass) then none of its methods can use a type 'b myclass
(where 'b 
differs from 'a...) in its params or return values.

ie:
  class type ['a] myclass =
  object method m : 'b -> 'b myclass end

is turned into
  class type ['a] myclass =
  object method m : 'a -> 'a myclass end

by the compiler


similarly:
  class type ['a] myclass =
  object method m : 'b myclass -> b end

is turned into
  class type ['a] myclass =
  object method m : 'a myclass -> 'a end

Does anybody agree with that ?
If yes, don't you feel it is an abnormal behaviour of the
compiler ?
Or else is there a good reason for it to behave like that ?

Thanks for your time,
Vincent





Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http:/
/groups.yahoo.com/group/ocaml_beginners/

<*> To unsubscribe from this group, send an email to:
    ocaml_beginners-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )