Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does F# not allow multiple attributes where C# does?

The following code compiles in C#:

[ContentType("text")]
[ContentType("projection")]
public class Class1
{
}

The following code in F# does not compile:

[<ContentType("text")>]
[<ContentType("projection")>]
type Class1() = class end

The compile error in F# is: "The attribute type 'ContentTypeAttribute' has 'AllowMultiple=false'. Multiple instances of this attribute cannot be attached to a single language element."

By decompiling ContentType, I can see that ContentType inherits from MultipleBaseMetadataAttribute which has 'AllowMultiple=true' in the AttributeUsage.

In fact, it seems like F# does not inherit the AttributeUsage from the parent class.

[<AttributeUsage(AttributeTargets.Class, AllowMultiple = true)>]
type FooAttribute() = 
    inherit Attribute()

type BarAttribute() =
    inherit FooAttribute()

[<Foo>]
[<Foo>]
type MyClassCompiles() = class end

where

[<Bar>]
[<Bar>]
type MyClassDoesNotCompile() = class end
like image 725
Johan Avatar asked Sep 27 '12 12:09

Johan


People also ask

Does Y equal f x?

Simply put, the Y=f(x) equation calculates the dependent output of a process given different inputs.

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 dash mean?

The first notation is to write f′(x) for the derivative of the function f(x). This functional notation was introduced by Lagrange, based on Isaac Newton's ideas. The dash in f′(x) denotes that f′(x) is derived from f(x).

What is the value of f (- 1?

The value of f(-1) is 1.


1 Answers

Looks like a bug. Email fsbugs[at]microsoft.com. Here's another apparent bug: it doesn't appear to honor AttributeTargets:

[<AttributeUsage(AttributeTargets.Enum)>]
type FooAttribute() = 
  inherit Attribute()

[<Foo>]
type T = struct end //happily compiles
like image 58
Daniel Avatar answered Oct 28 '22 00:10

Daniel