[
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: | 2005-09-14 (08:00) |
From: | Michael Wohlwend <micha-1@f...> |
Subject: | object question |
Hi, I want to make some chained object and an "apply" function on this chain. it might look as this (the functions don't make sense...yet :) ----------------------------------------------- class type tst = object method next: tst method clr: unit method apply: (tst -> unit) -> unit end;; let empty : tst = object(self) method next = self method clr = () method apply fkt = () end;; class test : tst = object(self) val mutable n = empty method clr = () method next = n method apply fkt = fkt (self :> tst) ; self#next#apply fkt (* Line 17 *) end;; let a = new test in a#apply (fun o -> o#clr) ---------------------------------------------------- first question, why do I have to cast self to tst in Line 17? The class test is defined to be of type tst, so self should allready be of type tst. But it works only with the cast. The other question, does this "apply" function use up the stack? Would it be better to define a tail-recursive apply outside the class? cheers Michael