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

Re: "ocaml_beginners"::[] Records and Variants

Expand Messages
  • Remi Vanicat
    ... Well, the : mean have the type , for example: - in {num: int; denum: int} the num field have the type int - in « val foo : bar » the function foo have
    Message 1 of 4 , Sep 3, 2003
    • 0 Attachment
      "vyvepe" <vyvepe@...> writes:

      > Warning: I'm very new to OCAML. I may need some patience :)
      >
      > Example:
      > type ratio = {num: int; denum: int};;
      > type number = Int of int | Float of float | Error;;
      >
      > I'm confused why recors use `:' to separate name and type and
      > variants use `of'. Why do not variants use colon too? Is there an
      > example where the difference between symbols is required to
      > disambiguate the source code meaning?

      Well, the : mean "have the type", for example:
      - in {num: int; denum: int} the num field have the type int
      - in « val foo : bar » the function foo have the type bar

      but in

      Int of int

      Int doesn't have the int type, its argument does.
      (One could say that the type of Int is int -> number, not int)

      --
      Rémi Vanicat
      vanicat@labri.u-bordeaux.fr
      http://dept-info.labri.u-bordeaux.fr/~vanicat
    • vyvepe
      Great, I like this answer, thanks.
      Message 2 of 4 , Sep 3, 2003
      • 0 Attachment
        Great, I like this answer, thanks.


        --- In ocaml_beginners@yahoogroups.com, Remi Vanicat
        <vanicat+egroups@l...> wrote:
        > "vyvepe" <vyvepe@y...> writes:
        >
        > > Warning: I'm very new to OCAML. I may need some patience :)
        > >
        > > Example:
        > > type ratio = {num: int; denum: int};;
        > > type number = Int of int | Float of float | Error;;
        > >
        > > I'm confused why recors use `:' to separate name and type and
        > > variants use `of'. Why do not variants use colon too? Is there an
        > > example where the difference between symbols is required to
        > > disambiguate the source code meaning?
        >
        > Well, the : mean "have the type", for example:
        > - in {num: int; denum: int} the num field have the type int
        > - in « val foo : bar » the function foo have the type bar
        >
        > but in
        >
        > Int of int
        >
        > Int doesn't have the int type, its argument does.
        > (One could say that the type of Int is int -> number, not int)
        >
        > --
        > Rémi Vanicat
        > vanicat@l...
        > http://dept-info.labri.u-bordeaux.fr/~vanicat
      Your message has been successfully submitted and would be delivered to recipients shortly.