F #: difference between type defined with and without parenthesis

What is the difference between type Something()and type Somethingin F #?

Why is this snippet mentioned in ASP.NET Core 1.0 F # project working:

open System
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.Http

type Startup() = 
    member this.Configure(app: IApplicationBuilder) =
      app.Run(fun context -> context.Response.WriteAsync("Hello from ASP.NET Core!"))

[<EntryPoint>]
let main argv = 
    let host = WebHostBuilder().UseKestrel().UseStartup<Startup>().Build()
    host.Run()
    printfn "Server finished!"
    0

but this fails:

open System
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.Http

type Startup = 
    member this.Configure(app: IApplicationBuilder) =
      app.Run(fun context -> context.Response.WriteAsync("Hello from ASP.NET Core!"))

[<EntryPoint>]
let main argv = 
    let host = WebHostBuilder().UseKestrel().UseStartup<Startup>().Build()
    host.Run()
    printfn "Server finished!"
    0
+4
source share
1 answer

You can see the difference by typing it in F # Interactive:

type Parens() =
    member this.add10 x = x + 10

type NoParens =
    member this.add10 x = x + 10;;

Conclusion:

type Parens =
  class
    new : unit -> Parens
    member add10 : x:int -> int
  end
type NoParens =
  class
    member add10 : x:int -> int
  end

The second class does not have a specific constructor. Something the compiler should not allow, but for some reason. It does not generate an automatic constructor such as C #.

F # classes interfaces. fooobar.com/questions/995437/...

, , F #, , , . , .

+7

All Articles