soebosi
7/25/2018 - 4:45 PM

ReasonML Class Syntax

ReasonML Class Syntax

class stack_of_ints = {
  as _self;
  val mutable the_list: list(int) = []; /* instance variable */
  pub push = x =>
    /* push method */
    the_list = [x, ...the_list];
  pub pop =
    {
      let result = List.hd(the_list);
      the_list = List.tl(the_list);
      result;
    } /* pop method */;
  pub peek =
    List.hd(the_list) /* peek method */;
  pub size =
    List.length(the_list) /* size method */;
};