我知道在OCaml中,可以创建一个执行以下操作的类:
class stack_of_ints =
object (self)
val mutable the_list = ( [] : int list ) (* instance variable *)
method push x = (* push method *)
the_list <- x :: the_list
end;;
但是,我一直在努力寻找有关如何在Reason中进行操作的文档。谢谢你。
最佳答案
没有很好地记录类和对象,因为与惯用的方法相比,这些功能增加了很多复杂性,(通常)带来的好处很少。但是,如果您知道OCaml语法的含义,则可以通过在线“Try Reason”游乐场对其进行转换,从而始终看到等效的原因。参见your example here,它给我们提供了这一点:
class stack_of_ints = {
as self;
val mutable the_list: list int = []; /* instance variable */
pub push x =>
/* push method */
the_list = [x, ...the_list];
};
关于OOP-如何在ReasonML中创建一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46219422/