I would like to create an object with a data member using OCaml but do not necessarily want to specify an initial value for the data member. Many examples seem to use a list but I would like to use a single instance of an object type I've created. Is this possible? Thanks.
class bar = object end;;
class foo =
object (self)
val myDataMember = ((* ??? *) : bar)
end;;
Additionally, I've tried the option keyword to no avail:
class bar =
object (self)
method doIt = Printf.printf "Doing it!"
end;;
class foo bar =
object (self)
val mutable myDataMember = (None : bar option)
method get = myDataMember
end;;
let f = new foo (new bar);;
f#get#bar#doIt;;
Here, the compiler complains about the data member having "bar option" type when I wished to specify it to have bar type.