functional programming - From the F# interactive, why would it not accept this? -


I am using F # CTP 1.9.7.8 and running samples based on Thomas Petris's article on page 12

 Type MyCell (n: int) = mutual data = n + 1 print "MyCell (create% d)" N member x.get () = Data and set with data (v) = Data & lt; - v member x Print () = printf "data% d" n override x.ToString () = sprintf "(data% d)" data static member FromInt (n) = MyCell (n) 

# Type in interactive:

  1. I got an error message as shown in Figure 1 below.
  2. Why a = next to member x.print () , x.ToString () but member X.Data not in Li>
  3. Where did x come? And why this happens when type MyCell is being defined, how can you reference 'object' in such a way, like x.print () , < Code> X.ToString () and x.Data ? Type myCell (n: int) = - Temporary data = n + 1 type myCell (n: int) = ----- ^^^^^^^ stdin ( 6,6): Error FS0547: One type of definition is required for one or more members or other announcements. If you intend to define an empty square, structure or interface, use 'type ... = class end', 'interface end' or 'straight end'. -

    Figure 1.

    Thanks, Best regards, Tom.

    As pblassucci said, you have to indent the contents of your class.

  4. print and toasting are methods, but data is a property, so the data For = and set methods.
  5. Instead of using an identifier such as this to refer to that class, whose members are being defined, F # is the identifier on the Member Member Member basis. Lets choose. The x is used in many instances, but the choice is arbitrary.

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -