Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does an F# type need to be initialised using new?

Given a class such as:

type MyClass() =
    member this.Greet(x) = printfn "Hello %s" x

is it appropriate to initialize instances using

let x = new MyClass()

or without the new?

Also, when is the use of a new constructor more useful than a do binding with parameters supplied to the type definition?

like image 979
Muhammad Alkarouri Avatar asked Aug 03 '10 17:08

Muhammad Alkarouri


People also ask

What is considered a high F value?

The F ratio is the ratio of two mean square values. If the null hypothesis is true, you expect F to have a value close to 1.0 most of the time. A large F ratio means that the variation among group means is more than you'd expect to see by chance.

What does an F-test tell you?

The F-test is used in regression analysis to test the hypothesis that all model parameters are zero. It is also used in statistical analysis when comparing statistical models that have been fitted using the same underlying factors and data set to determine the model with the best fit.

Can an F-statistic be negative?

The F-distribution cannot take negative values, because it is a ratio of variances and variances are always non-negative numbers. The distribution represents the ratio between the variance between groups and the variance within groups.

What does significance F mean in ANOVA?

The F-test of overall significance indicates whether your linear regression model provides a better fit to the data than a model that contains no independent variables.


2 Answers

My pattern in F# for using new is to only do so when the type implements IDisposable. The compiler special cases this use and emits a warning if new is omitted.

So in your case I would not use new. But with the following I would

type OtherClass() =
  ...
  interface System.IDisposable with 
    member this.Dispose() = ...

let x = new OtherClass()
like image 187
JaredPar Avatar answered Nov 15 '22 18:11

JaredPar


F# spec:

68 6.5.2 Object Construction Expressions An expression of the form new ty(e1 ... en) is an object construction expression and constructs a new instance of a type, usually by calling a constructor method on the type.

14.2.2 Item-Qualified Lookup The object construction ty(expr) is processed as an object constructor call as if it had been written new ty(expr).

F# compiler issues a warning if instance of type that implements IDisposable is created with Ty() syntax omitting new keyword. Spec says nothing about this fact, however I think it should definity should be mentioned.

like image 21
desco Avatar answered Nov 15 '22 17:11

desco