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

types of local bounded values

Expand Messages
  • Radu Grigore
    When I read a program written by someone else I find that seeing the inferred types helps. So I use ocamlc -i . But this does not show the types of locally
    Message 1 of 6 , Oct 1, 2004
    • 0 Attachment
      When I read a program written by someone else I find that seeing the
      inferred types helps. So I use "ocamlc -i". But this does not show
      the types of locally bound values. Example:

      let fact n =
      let rec tail_fact m = function
      | 1 -> m
      | n -> tail_fact (m*n) (n-1) in
      fact 1 n;;

      The "ocamlc -i" command will show
      fact : int -> int

      but not the type of the local function
      tail_fact : int -> int -> int

      Is there a way of seeing the infered types for localy bound values?

      regards,
      radu





      __________________________________
      Do you Yahoo!?
      Yahoo! Mail - 50x more storage than other providers!
      http://promotions.yahoo.com/new_mail
    • Stalkern 2
      ... (similar to Issac s way, but ...heuristically :-)) ) It happens to me to put a checkpoint by casting a item to a type, and watch for complaints. # let fact
      Message 2 of 6 , Oct 1, 2004
      • 0 Attachment
        Il Friday 01 October 2004 09:38, Radu Grigore ha scritto:
        > When I read a program written by someone else I find that seeing the
        > inferred types helps. So I use "ocamlc -i". But this does not show
        > the types of locally bound values. Example:
        >
        > let fact n =
        > let rec tail_fact m = function
        > | 1 -> m
        > | n -> tail_fact (m*n) (n-1) in
        > fact 1 n;;
        >
        > The "ocamlc -i" command will show
        > fact : int -> int
        >
        > but not the type of the local function
        > tail_fact : int -> int -> int
        >
        > Is there a way of seeing the infered types for localy bound values?
        >
        > regards,
        > radu

        (similar to Issac's way, but ...heuristically :-)) )
        It happens to me to put a checkpoint by casting a item to a type, and watch
        for complaints.

        # let fact n =
        let rec tail_fact m =
        function
        | 1 -> m
        | n -> (tail_fact:(int -> int)) (m*n) (n-1)
        in
        tail_fact 1 n;;
        Characters 80-89:
        | n -> (tail_fact:(int -> int)) (m*n) (n-1)
        ^^^^^^^^^
        This expression has type int -> int -> int but is here used with type
        int -> int


        Ernesto
      • Issac Trotts
        ... You can use the -dtypes compiler flag, though its output isn t very easy to read. It would be nicer if it displayed the results in terms of type
        Message 3 of 6 , Oct 1, 2004
        • 0 Attachment
          On Oct 1, 2004, at 12:38 AM, Radu Grigore wrote:

          >
          > When I read a program written by someone else I find that seeing the
          > inferred types helps. So I use "ocamlc -i". But this does not show
          > the types of locally bound values. Example:
          >
          > let fact n =
          > let rec tail_fact m = function
          > | 1 -> m
          > | n -> tail_fact (m*n) (n-1) in
          > fact 1 n;;
          >
          > The "ocamlc -i" command will show
          > fact : int -> int
          >
          > but not the type of the local function
          > tail_fact : int -> int -> int
          >
          > Is there a way of seeing the infered types for localy bound values?

          You can use the -dtypes compiler flag, though its output isn't very
          easy to read.
          It would be nicer if it displayed the results in terms of type
          constraints.
          For example

          let foo x =
          let a = x+1 in
          a

          would be displayed as

          let foo (x:int) =
          let (a:int) = x+1 in
          a

          The current implementation of -dtypes gives much more verbose output,
          with line
          and character numbers.

          -----
          Issac Trotts
          Programmer, NIMH Human Brain Project
          University of California, Davis
          http://mallorn.ucdavis.edu/conexus
        • Radu Grigore
          ... Thanks. It really does look ugly. And I don t know emacs :( (the manual says that it can be parsed by a set of emacs macros that come with the OCaml
          Message 4 of 6 , Oct 1, 2004
          • 0 Attachment
            --- Issac Trotts <ijtrotts@...> wrote:
            > You can use the -dtypes compiler flag, though its output
            > isn't very easy to read.

            Thanks. It really does look ugly. And I don't know emacs :(
            (the manual says that it can be parsed by a set of emacs macros that
            come with the OCaml distribution)

            regards,
            radu




            _______________________________
            Do you Yahoo!?
            Declare Yourself - Register online to vote today!
            http://vote.yahoo.com
          • Virgile Prevosto
            ... Hello, you might be interested by the -dtypes option of ocamlc: it generates a file.annot file with detailed type informations - as says the manual.
            Message 5 of 6 , Oct 1, 2004
            • 0 Attachment
              Le 01.10.2004, à 00:38:02, Radu Grigore a écrit:
              >
              > When I read a program written by someone else I find that seeing the
              > inferred types helps. So I use "ocamlc -i". But this does not show
              > the types of locally bound values. Example:

              Hello,
              you might be interested by the -dtypes option of ocamlc: it generates a
              file.annot file with "detailed type informations" - as says the manual.
              Then, if you're using (x)emacs, some commands to display these
              informations are provided in the caml-types.el (emacs directory of the
              ocaml sources). In particular, caml-types-show-type shows the type of
              the expression currently pointed at in the main buffer.

              --
              E tutto per oggi, a la prossima volta
              Virgile
            • Remi Vanicat
              ... It s made for been read by inteligent editor. The ocaml mode is able to do it.
              Message 6 of 6 , Oct 1, 2004
              • 0 Attachment
                On Fri, 1 Oct 2004 00:56:27 -0700, Issac Trotts <ijtrotts@...> wrote:
                >
                > On Oct 1, 2004, at 12:38 AM, Radu Grigore wrote:
                >
                > >
                > > When I read a program written by someone else I find that seeing the
                > > inferred types helps. So I use "ocamlc -i". But this does not show
                > > the types of locally bound values. Example:
                > >
                > > let fact n =
                > > let rec tail_fact m = function
                > > | 1 -> m
                > > | n -> tail_fact (m*n) (n-1) in
                > > fact 1 n;;
                > >
                > > The "ocamlc -i" command will show
                > > fact : int -> int
                > >
                > > but not the type of the local function
                > > tail_fact : int -> int -> int
                > >
                > > Is there a way of seeing the infered types for localy bound values?
                >
                > You can use the -dtypes compiler flag, though its output isn't very
                > easy to read.

                It's made for been read by inteligent editor. The ocaml mode is able to do it.
              Your message has been successfully submitted and would be delivered to recipients shortly.