Browse thread
Bug? Constraints get ignored in methods
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ 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:
> Hi,
>
> small add on to my last mail.
>
> Think of it as having a set of work queues: clean, dirty, reading,
> writing, write_prepare. The objects need to be able to quickly jump
> from one queue to the back of another when the objects internal state
> changes. And is not only the objects at the head of the queue that
> change states. Can be pretty random what object changes.
>
> If I put the prev/next links into the objects themself they can easily
> detach themself from a queue and insert themself into another.
>
> If I put the objects into other generic queue structures then I have to
> find the position in the old queue to remove an object and that would
> be slow.
>
>
> If you can think of a solution that would allow
>
> type 'a data = { next : 'b data option; data : 'a }
>
> without having to know possibly types of 'b then I could use functors.
>
> This would have to work:
>
> let s = { next = None; data = "string" }
> let i = { next = Some s; data = 23 }
Would the following work for you:
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
let s = create (new s) None
let i = create (new i) (Some s)
val create : 'a -> < .. > linked option -> 'a linked = <fun>
val set_next : 'a linked -> < .. > linked option -> unit = <fun>
class s : object method s : string end
class i : object method i : int end
val s : s linked = {data = <obj>; next = None}
val i : i linked = {data = <obj>; next = Some {data = <obj>; next = None}}
--
http://mjambon.com/