如何在 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}
....
但编译器声称这一行是语法错误: typegun = {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}
....
错误是:unbound valuegun。
那么有人知道如何用另一种方式达到相同的功能吗? 谢谢你!
********** 解决了***
奇怪的是,现在当类型在外部声明时它就可以工作了,谢谢
I wanna declare a record inside a class as follows:
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}
....
but the compiler claim that this line is syntax error : type gun = {x:in ....
when declared outside the class like this
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}
....
the error is : unbound value gun.
so anyone know how to reach the same functionality with another way?
thank you!
********* solved***
Bizare now it's working when the type is declared outside, thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不在类定义之外定义类型枪?
Why don't you define the type gun outside of the class definition?