我在OCaml中遇到了列表问题。我读过冲突的陈述,说明列表是否可以在运行时修改。 cons运算符可以在运行时使用吗?OCaml结构类型和列表
此外,为什么杜宾犬(见下文)允许在吉娃娃列表中?一个人如何将另一个奇瓦瓦州加入名单(如最后一行所示)?
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;;