Class 如何在OCAML类中声明记录

Class 如何在OCAML类中声明记录,class,object,class-design,ocaml,Class,Object,Class Design,Ocaml,我想在类中声明一条记录,如下所示: class player (x, y)= object(self) type gun = {x:int; y:int; active:bool} val guns = Array.create 5 {x=0; y=0; active=false} .... 但是编译器声称这一行是语法错误:type gun={x:in 当像这样在类外声明时 type : gun = {x:int; y:int; active:bool} cla

我想在类中声明一条记录,如下所示:

class player (x, y)=
     object(self)
     type gun = {x:int; y:int; active:bool}
     val guns = Array.create 5 {x=0; y=0; active=false}
....
但是编译器声称这一行是语法错误:type gun={x:in

当像这样在类外声明时

type :  gun = {x:int; y:int; active:bool}
class player (x, y)=
     object(self)
     val guns = Array.create 5 {x=0; y=0; active=false}
....
错误是:未绑定值gun

那么,有人知道如何通过另一种方式实现相同的功能吗? 谢谢大家!

*********解决***


Bizare现在,当类型在外部声明时,它正在工作,谢谢

为什么不在类定义之外定义类型gun?

当我在类之外声明它时,它说:unbound value gun。