Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does F# allow attributes that don't inherit from System.Attribute?

Tags:

f#

I created an F# 'Nunit' project using a template in VS 2019 to do some testing, and the default fixture code it created was the following:

namespace Tests

open NUnit.Framework

[<TestClass>]
type TestClass () =

    [<SetUp>]
    member this.Setup () =
        ()

    [<Test>]
    member this.Test1 () =
        Assert.Pass()

It's an otherwise ordinary looking class, except the curiosity on the class declaration. I expected to see [<TestFixture>], but instead I see [<TestClass>], the same name as the auto-generated type. I suspect that this is a bug in the project template, but strangely, F# will happily compile this, with a note that it probably won't be compatible with other .Net languages:

warning FS3242: This type does not inherit Attribute, it will not work correctly with other .NET languages.

crystal clear for me. My question is, why does F# even allow this? Do the reflection capabilities in .Net even work for such an attribute in F#? What would a potential use-case be?

like image 421
Jeff Dammeyer Avatar asked Jan 19 '19 19:01

Jeff Dammeyer


People also ask

What does f apostrophe mean?

This formula, or new function, is called the derivative of the original function. When we find it we say that we are differentiating the function. The derivative of f(x) is written using an apostrophe after the f. The notation is f´(x) or y´ The notation dy/dx is also commonly used.

What does f represent in calculus?

we mean the derivative of the function f ( x ) with respect to the variable x . One type of notation for derivatives is sometimes called prime notation. The function f ´( x ), which would be read `` f -prime of x '', means the derivative of f ( x ) with respect to x .

What does f mean in math?

more ... A special relationship where each input has a single output. It is often written as "f(x)" where x is the input value. Example: f(x) = x/2 ("f of x equals x divided by 2")

Is f x the same as Y?

An equation is a relationship between variables. Yes, y=x+3 and f(x)= x+3 yield the same results, which is why we teachers always tell you to remember that 'y and f(x) are the same thing'.


1 Answers

Historically the check was forgotten to be added to the compiler. When it was discovered, I propose to make it compilation error, but it ended up as a warning for backward compatible reasons. See https://github.com/Microsoft/visualfsharp/pull/5192 and https://github.com/Microsoft/visualfsharp/pull/5610 for details.

like image 186
Vasily Kirichenko Avatar answered Oct 05 '22 23:10

Vasily Kirichenko