f# - call abstract function from a method's own implementation -


i have tried call abstract function method's own implementation.

[<abstractclass>] type callanabstract () =       let dosomethingelse () = printfn "done something.."      abstract dosomethingabstract: unit -> unit      member this.dosomething =         printfn "done something.."         dosomethingelse ()         dosomethingabstract () 

which results in error:

error fs0039: value or constructor 'dosomethingabstract' not defined

is calling abstract function method's own implementation illegal or problem lie somewhere else?

if being illegal case, here (see answer) @mark seemann explains composition on inheritance:

[<abstractclass>] type usecomposition (dosomethingelsedefinedlater) =       let dosomethingelse () = printfn "done something.."      member this.dosomething =         printfn "done something.."         dosomethingelse ()         dosomethingelsedefinedlater () 

what alternatives? i'd avoid passing function via constructor , i'd reuse code, having dosomething have "some implementation" until call abstract function.

you need use this reference:

this.dosomethingabstract() 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -