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

Extending polymorphic types

Expand Messages
  • hmf@inescporto.pt
    Hello, I am trying to code a planner whose base input is a type: type a problem = { goal : a ; initially : a ; always : a list ; operator : a list } The
    Message 1 of 5 , Jul 31, 2008
    • 0 Attachment
      Hello,

      I am trying to code a planner whose base input is a type:

      type 'a problem = {
      goal : 'a ;
      initially : 'a ;
      always : 'a list ;
      operator : 'a list
      }


      The idea is that 'a may be either described using propositional
      or predicate logic. So that it can be used to defined:

      type prop_problem = Prop.expr problem
      type pred_problem = Pred.expr problem

      However the predicate version of the problem requires additional
      fields (domain and range).

      My question is: is their a way to use a "base" type and extend it
      so that I can still use the "." to access all fields:

      let p1 = make_pred_problem input in
      let g = p1.goal in
      let d = p1.domain in
      ...

      Any other suggestion on how best to deal with this?

      TIA,
      Hugo F.
    • Richard Jones
      ... What would be the type of a function which accessed the extended fields? let f p = ignore (p.range) val f : ?? - unit versus a function which didn t need
      Message 2 of 5 , Jul 31, 2008
      • 0 Attachment
        On Thu, Jul 31, 2008 at 08:21:44AM +0100, hmf@... wrote:
        > My question is: is their a way to use a "base" type and extend it
        > so that I can still use the "." to access all fields:

        What would be the type of a function which accessed the extended
        fields?

        let f p = ignore (p.range)

        val f : ?? -> unit

        versus a function which didn't need to access the extended fields?

        I think you should use objects for this.

        Rich.

        --
        Richard Jones
        Red Hat
      • hmf@inescporto.pt
        ... Two functions one for each type. Come to think of it... I seem to gain nothing by extending the structure. Base types are different anyway. Back to the
        Message 3 of 5 , Jul 31, 2008
        • 0 Attachment
          Richard Jones wrote:
          > On Thu, Jul 31, 2008 at 08:21:44AM +0100, hmf@... wrote:
          >> My question is: is their a way to use a "base" type and extend it
          >> so that I can still use the "." to access all fields:
          >
          > What would be the type of a function which accessed the extended
          > fields?
          >
          > let f p = ignore (p.range)
          >
          > val f : ?? -> unit
          >
          > versus a function which didn't need to access the extended fields?
          >

          Two functions one for each type.
          Come to think of it... I seem to gain nothing
          by "extending" the structure. Base types are
          different anyway.

          Back to the drawing board 8-(

          > I think you should use objects for this.
          >

          Don't want to use the object system because I don't know it.
          Take way too long to learn it.

          Thanks for the feedback.
          Hugo F.


          > Rich.
          >
        • Peng Zang
          ... Hash: SHA1 ... Out of curiosity, what is always and what is operator ? Are they your actions? Because if they are, I would expect them to be ( a -
          Message 4 of 5 , Jul 31, 2008
          • 0 Attachment
            -----BEGIN PGP SIGNED MESSAGE-----
            Hash: SHA1


            On Thursday 31 July 2008 03:21:44 am hmf@... wrote:
            > Hello,
            >
            > I am trying to code a planner whose base input is a type:
            >
            > type 'a problem = {
            > goal : 'a ;
            > initially : 'a ;
            > always : 'a list ;
            > operator : 'a list
            > }
            >

            Out of curiosity, what is "always" and what is "operator"? Are they your
            actions? Because if they are, I would expect them to be ('a -> 'a) list...

            Peng
            -----BEGIN PGP SIGNATURE-----
            Version: GnuPG v2.0.7 (GNU/Linux)

            iD8DBQFIkZV7fIRcEFL/JewRAk3HAKCn1RwClnbtTkqDzty/ZwpmN1Nx8ACgyMdR
            AQLuxpIG4HitPLYhf7V0H2k=
            =rta/
            -----END PGP SIGNATURE-----
          • hmf@inescporto.pt
            Hi, ... The a are either propositional logic formula or first order logic formula. Always - consists of a set of a formula (must always be true), Operator -
            Message 5 of 5 , Jul 31, 2008
            • 0 Attachment
              Hi,

              Peng Zang wrote:
              > -----BEGIN PGP SIGNED MESSAGE-----
              > Hash: SHA1
              >
              >
              > On Thursday 31 July 2008 03:21:44 am hmf@... wrote:
              >> Hello,
              >>
              >> I am trying to code a planner whose base input is a type:
              >>
              >> type 'a problem = {
              >> goal : 'a ;
              >> initially : 'a ;
              >> always : 'a list ;
              >> operator : 'a list
              >> }
              >>
              >
              > Out of curiosity, what is "always" and what is "operator"? Are they your
              > actions? Because if they are, I would expect them to be ('a -> 'a) list...
              >

              The 'a are either propositional logic formula or first order logic formula.

              Always - consists of a set of 'a formula (must always be true),
              Operator - set of operators (encoded as state transitions). Each
              operator is nothing but an 'a formula.

              These formula are then used to "solve" the planning problem.

              Hugo F.


              > Peng
              > -----BEGIN PGP SIGNATURE-----
              > Version: GnuPG v2.0.7 (GNU/Linux)
              >
              > iD8DBQFIkZV7fIRcEFL/JewRAk3HAKCn1RwClnbtTkqDzty/ZwpmN1Nx8ACgyMdR
              > AQLuxpIG4HitPLYhf7V0H2k=
              > =rta/
              > -----END PGP SIGNATURE-----
              >
              > ------------------------------------
              >
              > Archives up to December 31, 2007 are also downloadable at
              http://www.connettivo.net/cntprojects/ocaml_beginners/
              > The archives of the very official ocaml list (the seniors' one) can be found
              at http://caml.inria.fr
              > Attachments are banned and you're asked to be polite, avoid flames etc.Yahoo!
              Groups Links
              >
              >
              >
              >
            Your message has been successfully submitted and would be delivered to recipients shortly.