On Fri, 28 Jul 2006, vincent.aravantinos wrote:
> --- 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 ?
Looks like it.
# let rec f a b = f b a;;
val f : 'a -> 'a -> 'b = <fun>
(not 'a -> 'b -> 'c)
That's the record version of your class where the map
method is not
polymorphic:
# type ('a, 'b) t = { list : 'a list; map : ('a ->
'b) -> ('a, 'b) t };;
type ('a, 'b) t = { list : 'a list; map : ('a -> 'b)
-> ('a, 'b) t; }
# let rec create l = { list = l; map = fun f -> create
(List.map f l) };;
val create : 'a list -> ('a, 'a) t = <fun>
And it's not possible to make the map method polymorphic
because 'b will
be equal to 'a, which is fixed because of the list field:
# type 'a t = { list : 'a list; map : 'b.('a -> 'b)
-> 'b t };;
type 'a t = { list : 'a list; map : 'b. ('a -> 'b)
-> 'b t; }
# let rec create l = { list = l; map = fun f -> create
(List.map f l) };;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This field value has type ('a -> 'a) -> 'a t which
is less general than
'b. ('c -> 'b) -> 'b t
Using tuples and the -rectypes option it goes like this:
# let rec create l = (l, fun f -> create (List.map f
l));;
val create : 'a list -> ('a list * (('a -> 'a)
-> 'b) as 'b) = <fun>
so we still have the problem that all the occurrences of
create
are unified to the same type.
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/
|