hubFS: THE place for F#

. . . are you on The Hub?
Welcome to hubFS: THE place for F# Sign in | Join | Help
in Search

Constructors and property setters

Last post 08-05-2008, 14:57 by dsyme. 1 replies.
Sort Posts: Previous Next
  •  08-05-2008, 0:32 6515

    Constructors and property setters

    I was wondering about this syntax:

    let form = new Form(Visible=true,TopMost=true,Text="Welcome to F#")

    from the Expert F# book:

    The labels Visible, TopMost, and Text must correspond

    to either named arguments of the constructor being called or properties on the return

    result of the operation.

    I wonder why use the same syntax to call constructor and property setters. How am I to know if a constructor is called or properties are set when reading the code? Also if this is not coming from OCaml and the only reason is to integrate with .NET why not use a syntax that .NET programmers are familiar with i.e. the C# 3.0 syntax where constructors are called with () and property setters are inside { }? I wonder what is the reasoning behind the current F# syntax. Maybe I'm missing something.

  •  08-05-2008, 14:57 6520 in reply to 6515

    Re: Constructors and property setters

    Hi Stilgar,

    By .NET convention arguments have lower case names and properties upper-case, so it is in paractice easy to tell the difference, at least when using idiomatic .NET libraries (which can, of course, be written i F#)

    We trialled several versions of this syntax internally last year. The general feeling was that the simplicity and regularity of allowing both named properties and named arguments as labelled parameters was best for F#. It was in part inspired by named-argument syntax in languages such as Boo.

    Kind regards

    Don

    P.S. In the CTP release of F#, hovering over the names "Visible" etc. will give a hover tip indicating the resolution of the name. Just wait for Brian's screen shots :-)

     

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems