Loading ...
Sorry, an error occurred while loading the content.

Parameterized Classes

Expand Messages
  • dpthayer2004
    I have a class I have created that takes three parameters class lc_classifier (condition:lc_condition) (_action:lc_action) (_params:lc_exp_params) = ...etc
    Message 1 of 2 , Feb 3, 2004
    • 0 Attachment
      I have a class I have created that takes three parameters

      class lc_classifier
      (condition:lc_condition)
      (_action:lc_action)
      (_params:lc_exp_params) = ...etc

      When I use this class at some other point of my program

      i.e.

      (*Create a population with n randomized classifiers*)
      method populate n =
      let c = params#get_cond_size;
      and g = params#get_generality;
      and a = params#get_actions_num;
      in
      for i = 1 to n do
      let cnd = LC_Condition ( random_condition c g);
      and act = LC_Action( random_action a);
      in
      let p = new lc_classifier cnd act params
      in
      self#insert_classifier p;
      done

      which is a method n a different class I am getting the followng
      error message when I try to load it in the OCaml Interpreter.

      File "G:/OCaml/LCS_Population.ml", line 64, characters 36-39:
      This expression has type lc_condition but is here used with type
      lc_condition The line triggering the error is

      let p = new lc_classifier cnd act params

      and the specific token fingered is the token 'cnd'

      Can anyone tell me what I am doing wrong. I am relatively new to
      OCaml but have studied the tutorials assidously.

      Thanks

      David Thayer
    • Remi Vanicat
      ... This is because you define the type lc_condition at least two time. Ocaml don t give you warning when you do it (may be it should), but thus strange error
      Message 2 of 2 , Feb 3, 2004
      • 0 Attachment
        "dpthayer2004" <methayer@...> writes:

        > I have a class I have created that takes three parameters
        >
        > class lc_classifier
        > (condition:lc_condition)
        > (_action:lc_action)
        > (_params:lc_exp_params) = ...etc
        >
        > When I use this class at some other point of my program
        >
        > i.e.
        >
        > (*Create a population with n randomized classifiers*)
        > method populate n =
        > let c = params#get_cond_size;
        > and g = params#get_generality;
        > and a = params#get_actions_num;
        > in
        > for i = 1 to n do
        > let cnd = LC_Condition ( random_condition c g);
        > and act = LC_Action( random_action a);
        > in
        > let p = new lc_classifier cnd act params
        > in
        > self#insert_classifier p;
        > done
        >
        > which is a method n a different class I am getting the followng
        > error message when I try to load it in the OCaml Interpreter.
        >
        > File "G:/OCaml/LCS_Population.ml", line 64, characters 36-39:
        > This expression has type lc_condition but is here used with type
        > lc_condition The line triggering the error is

        This is because you define the type lc_condition at least two
        time. Ocaml don't give you warning when you do it (may be it should),
        but thus strange error message when you use something of one of the
        type when you mean the other. So you have to look where is the
        multiple definition of the lc_condition type, knowing the fact that a
        class definition is at the same time a type definition.

        Hope that help.

        --
        Rémi Vanicat
      Your message has been successfully submitted and would be delivered to recipients shortly.