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

consensus sapientum

Expand Messages
  • Jean Saint-Remy
    Hi,   Unanimity of the wise in silence I gather indicates consensus.  There is no way to access types when using constructor unless we are talking about the
    Message 1 of 4 , Apr 19, 2013
    • 0 Attachment
      Hi,
       
      Unanimity of the wise in silence I gather indicates consensus.  There is no way to access types when using constructor unless we are talking about the object system. The simple indirection is all that is available.
       
      type db = {
        name : string;
        phone : int;
        salary : float;
      } ;;
       
      let bob = { name = "Bob Jones"; phone = 2125824678; salary = 130000.00; } ;;
      bob.phone ;;
      -: val int = 2125824678
       
      The above construct is not at all useful. Ocaml is not Ruby. If you want Ocaml, try this instead
       
      type 'a nugget =
        | Fools_gold
        | Yellow_gold of 'a
                                  * ('a nugget)
                                  * ('a nugget)
      ;;
       
      If we want to access the individual fields, we don't use the constructors, we are functional programmers,
      we chew instead.
       
      let rec prospect (nugget : 'a nugget ) : 'a list = match nugget with
        | Fools_gold -> []
        | Yellow_gold -> (tinpan, handful, riverbed) ->
          tinpan :: (List.append (prospect handful) (prospect riverbed)) ;;
       
      If we want to create an instance, we can use a constructor, but this does not get us anywhere.
       
      let blah = Fools_gold ;;
      let got_one = Yellow_gold (1, blah, blah) ;;
       
      With kind regards,
       
      Jean

      [Non-text portions of this message have been removed]
    • Gabriel Scherer
      ... Silence means what the heck? . I don t understand any of what you say. Records are built with the { foo = ... ; bar = ... } notation, and deconstructed by
      Message 2 of 4 , Apr 19, 2013
      • 0 Attachment
        > Unanimity of the wise in silence I gather indicates consensus.

        Silence means "what the heck?". I don't understand any of what you say.

        Records are built with the { foo = ... ; bar = ... } notation, and
        deconstructed by field projection r.foo, or pattern matching (match x
        with { foo = p; ... } -> ...). Sums are built with the constructors,
        and deconstructed by pattern-matching.

        On Fri, Apr 19, 2013 at 9:08 PM, Jean Saint-Remy
        <jeansaintremy@...> wrote:
        > Hi,
        >
        > Unanimity of the wise in silence I gather indicates consensus. There is no way to access types when using constructor unless we are talking about the object system. The simple indirection is all that is available.
        >
        > type db = {
        > name : string;
        > phone : int;
        > salary : float;
        > } ;;
        >
        > let bob = { name = "Bob Jones"; phone = 2125824678; salary = 130000.00; } ;;
        > bob.phone ;;
        > -: val int = 2125824678
        >
        > The above construct is not at all useful. Ocaml is not Ruby. If you want Ocaml, try this instead
        >
        > type 'a nugget =
        > | Fools_gold
        > | Yellow_gold of 'a
        > * ('a nugget)
        > * ('a nugget)
        > ;;
        >
        > If we want to access the individual fields, we don't use the constructors, we are functional programmers,
        > we chew instead.
        >
        > let rec prospect (nugget : 'a nugget ) : 'a list = match nugget with
        > | Fools_gold -> []
        > | Yellow_gold -> (tinpan, handful, riverbed) ->
        > tinpan :: (List.append (prospect handful) (prospect riverbed)) ;;
        >
        > If we want to create an instance, we can use a constructor, but this does not get us anywhere.
        >
        > let blah = Fools_gold ;;
        > let got_one = Yellow_gold (1, blah, blah) ;;
        >
        > With kind regards,
        >
        > Jean
        >
        > [Non-text portions of this message have been removed]
        >
        >
        >
        > ------------------------------------
        >
        > Archives up to December 31, 2011 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
        >
        >
        >
      • Francois Berenger
        ... Hello, Since when is it possible to do pattern matching on records? I thought a syntax extension was needed for this (some janestreet one). Thanks, F.
        Message 3 of 4 , Apr 21, 2013
        • 0 Attachment
          On 04/20/2013 06:00 AM, Gabriel Scherer wrote:
          > > Unanimity of the wise in silence I gather indicates consensus.
          >
          > Silence means "what the heck?". I don't understand any of what you say.
          >
          > Records are built with the { foo = ... ; bar = ... } notation, and
          > deconstructed by field projection r.foo, or pattern matching (match x
          > with { foo = p; ... } -> ...).

          Hello,

          Since when is it possible to do pattern matching on records?

          I thought a syntax extension was needed for this (some janestreet one).

          Thanks,
          F.
        • Lukasz Stafiniak
          ... Since always... Although with new features since OCaml 3.12. http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#toc78 [Non-text portions of this
          Message 4 of 4 , Apr 21, 2013
          • 0 Attachment
            On Mon, Apr 22, 2013 at 2:25 AM, Francois Berenger <berenger@...>wrote:

            > **
            >
            >
            > On 04/20/2013 06:00 AM, Gabriel Scherer wrote:
            > >
            > > Records are built with the { foo = ... ; bar = ... } notation, and
            > > deconstructed by field projection r.foo, or pattern matching (match x
            > > with { foo = p; ... } -> ...).
            >
            > Hello,
            >
            > Since when is it possible to do pattern matching on records?
            >
            > I thought a syntax extension was needed for this (some janestreet one).
            >
            >
            Since always... Although with new features since OCaml 3.12.
            http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#toc78


            [Non-text portions of this message have been removed]
          Your message has been successfully submitted and would be delivered to recipients shortly.