From: David B. <dav...@gm...> - 2013-03-20 09:31:45
|
Hi Leonard, Using a reference to break this circularity problem is the right solution. We don't have a simpler solution for now, although we have this in mind for a few potential language extensions. On Wed, Mar 20, 2013 at 12:38 AM, Leonard de Ruijter <lee...@le...> wrote: > register_source=ref fun ()->() > src = input.harbor(...,on_connect=!register_source()) > register_source:=see function above > I however don't know how to create the reference variable itself. I get > this kind of errors: > At line 44, char 16-17: > this value has type > ref((...)->unit) (infered at line 31 char 17 - line 36 char 3) > but it should be a subtype of (the type of the value at line 44 char > 16 - line > 50 char 3) > ref((...)->source(_)) It's probably only a "small" syntax or type error. For instance, you cannot write !register_source(), it is understood as !(register_source()). Unfortunately, you cannot fix it by writing (!register_source)() either -- it's a rigidity of our syntax that is necessary to allow nice things such as not writing semicolons after each instruction. Finally, on_connect takes an argument but your register_source function does not. Long story short, I recommend writing it as follows: register_source = ref (fun () -> ()) def call_register_source(_) f = !register_source f() end src = input.harbor(...,on_connect=call_register_source) register_source := ... Hope this helps, -- David |