ocaml - Having trouble creating arbitrary new Object, parametrized for function call -


i wanted kind of expression in ocaml

let wrapper obj f = fun raw -> f (new obj raw) 

but compiler error of unbound class obj what, why isn't compiler satisfied creating function says call function on object happens take 1 init arg.

pass function constructs object. one-argument class foo can use new foo function.

let wrapper make_obj f raw = f (make_obj raw)  class foo (x) = object   method y = x + 1 end  let answer = wrapper (new foo) (fun o -> o#y) 2 

here, wrapper has general type doesn't mention objects @ all. if want make clear object constructor expected argument, can restrict type annotation:

let wrapper (make_obj: (_ -> < .. >)) f raw = f (make_obj raw) 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -