OOP - How to create a class in ReasonML

I know that in OCaml you can create a class by doing the following:

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;; 

However, I struggled to find documentation on how to do this in Reason. Thanks.

+5
source share
1 answer

Classes and objects are not well documented, because these functions greatly complicate (usually) very few advantages compared to the more idiomatic approach. But if you know the OCaml syntax for something, you can always see what the equivalent of Reason is when converting it with the Try Reason online platform. See your example here , which gives us the following:

 class stack_of_ints = { as self; val mutable the_list: list int = []; /* instance variable */ pub push x => /* push method */ the_list = [x, ...the_list]; }; 
+5
source

Source: https://habr.com/ru/post/1271797/


All Articles