Version française
Home     About     Download     Resources     Contact us    
Browse thread
Bug? Constraints get ignored in methods
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Martin Jambon <martin.jambon@e...>
Subject: Re: [Caml-list] Bug? Constraints get ignored in methods
Goswin von Brederlow wrote:
> Martin Jambon <martin.jambon@ens-lyon.org> writes:
> 
>> Would the following work for you:
> 
> No. Not just like this.
> 
>> type 'a linked = {
>>   data : 'a;
>>   mutable next : < > linked option
>> }
>> (* constraint 'a = < .. > *)
>>
>> let create data next = {
>>   data = data;
>>   next = (next :> < > linked option)
>> }
>>
>> let set_next x y =
>>   x.next <- (y :> < > linked option)
>>
>>
>> class s =
>> object
>>   method s = "abc"
>> end
>>
>> class i =
>> object
>>   method i = 123
>> end
> 
> class s and i have no access to the linked type.

Yes, that's exactly what I'm trying to achieve.
They are contained in cells of the list.
You need to handle cells if you want to change the linkage.

> You could not remove
> a class s or i from the linked structure in O(1) from within class s
> or i. So linked would have to handle any function that might require
> altering the linked structure and pass parts of it to its data. But
> data is an unknown type so no method of it can be called.

< > is your base class. Replace it by whatever you like.


Martin

-- 
http://mjambon.com/