I'm having trouble with lists in OCaml. I've read conflicting statements saying whether or not the lists can be modified at runtime. Can the cons operator be used at runtime?
Additionally, why is a doberman (see below) allowed to be in a list of chihuahuas? How would one go about adding another chihuahua onto the list (as attempted with the last line)?
class virtual dog =
object
method virtual bark : unit
end;;
class chihuahua =
object
inherit dog
method bark = Printf.printf "Yip!"
end;;
class doberman =
object
inherit dog
method bark = Printf.printf "Roar!"
end;;
let c1 = new chihuahua;;
let c2 = new chihuahua;;
let c3 = new chihuahua;;
let d1 = new doberman;;
let arrayOfDogs = [c1;c2;d1];;
arrayOfDogs :: c3;;