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

13881Re: accessing record types

Expand Messages
  • Rémi Vanicat
    Apr 16 10:07 AM
    • 0 Attachment
      Jean Saint-Remy <jeansaintremy@...> writes:

      > I don't know how to adequately describe 2nd order of abstraction here. My apologies for the omission. Typically the
      > 'type' declaration does not involve dangling modifier using "of". I am using Person of entry and then break it down into
      > strings for first and last names, but inside a database you have a lot of non-sequteur, heterogenous collections. I want to
      > understand how the type engine allows us to work with strings, numbers, booleans, etc. If you are in the car parts
      > department, an auto part might have a description, manufacturer part number, secondary market part number, a boolean
      > if it is in the inventory, the price may be in floats and item count in ints.
      >

      I don't really understand your question, could you show us an example of
      something that doesn't work for us to comment on?

      As an explanation, I can say that:

      type a_record = {
      foo : string;
      bar : int
      }

      define a new type that is a record (not a variant). It have two field,
      the first one named foo, containing string, the second one named bar
      containing int.

      All value of type new_type will have the very same structure, they can
      be build by { foo = "a string"; bar = 3 }, and the field can be accessed
      by the dot notation.

      This must not be mistaken with variant type like:

      type a_variant =
      | Foo of string
      | Bar of int

      Note the capital letter at the beginning of the name of both
      constructor: they are very (very) different thing than the field name of
      the record.

      Here value of type a_variant can have two different structure: either
      they are in the Foo case, and contain a string, or are in the Bar case,
      and will contain an int.

      For variant, value will be accessed using a patter matching that will:
      - Test in wich case we are, to act in a different way
      - Deconstruct the value to have the included value (here, either a
      string or an int, but not both)

      [...]


      --
      Rémi Vanicat
    • Show all 6 messages in this topic