From 04b4cbcd27178cc053fdd42b8f4db475a0aa4196 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Oct 2025 19:26:18 +0000 Subject: [PATCH 1/3] Initial plan From e37042cd6b7b433f9c7ecfc2302a8a6f9fbc1ffd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Oct 2025 19:32:49 +0000 Subject: [PATCH 2/3] Add documentation for empty/marker interfaces in F# Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- docs/fsharp/language-reference/interfaces.md | 10 ++++++++++ samples/snippets/fsharp/lang-ref-1/snippet2806.fs | 13 +++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 samples/snippets/fsharp/lang-ref-1/snippet2806.fs diff --git a/docs/fsharp/language-reference/interfaces.md b/docs/fsharp/language-reference/interfaces.md index da20bc7f12c2d..9a17c352b72fb 100644 --- a/docs/fsharp/language-reference/interfaces.md +++ b/docs/fsharp/language-reference/interfaces.md @@ -72,6 +72,16 @@ You can implement one or more interfaces in a class type by using the `interface Interface implementations are inherited, so any derived classes do not need to reimplement them. +## Implementing empty or marker interfaces + +Empty interfaces, also known as marker interfaces, can be used to identify a set of types without requiring any specific behavior. These interfaces have no members and serve as a way to mark or tag types for categorization purposes. + +You define an empty interface using the `interface end` syntax: + +[!code-fsharp[Main](~/samples/snippets/fsharp/lang-ref-1/snippet2806.fs)] + +In the example above, `IMarker` is defined as an empty interface. Both `MyRecord` and `MyClass` implement this interface without needing to provide any method implementations, since the interface has no members. This allows you to use the interface type to identify and work with these types in a common way. + ## Calling Interface Methods Interface methods can be called only through the interface, not through any object of the type that implements the interface. Thus, you might have to upcast to the interface type by using the `:>` operator or the `upcast` operator in order to call these methods. diff --git a/samples/snippets/fsharp/lang-ref-1/snippet2806.fs b/samples/snippets/fsharp/lang-ref-1/snippet2806.fs new file mode 100644 index 0000000000000..3bbf10d85a8ff --- /dev/null +++ b/samples/snippets/fsharp/lang-ref-1/snippet2806.fs @@ -0,0 +1,13 @@ +// Define an empty interface (also known as a marker interface) +type IMarker = + interface end + +// Implement the empty interface in a record type +type MyRecord = + { Name: string } + interface IMarker + +// Implement the empty interface in a class type +type MyClass(value: int) = + member _.Value = value + interface IMarker From 703b9dcfec8c07fa5d80aab8d4eb4b075ab75c7d Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Fri, 10 Oct 2025 10:01:12 -0400 Subject: [PATCH 3/3] Update docs/fsharp/language-reference/interfaces.md --- docs/fsharp/language-reference/interfaces.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fsharp/language-reference/interfaces.md b/docs/fsharp/language-reference/interfaces.md index 9a17c352b72fb..513a992d12f86 100644 --- a/docs/fsharp/language-reference/interfaces.md +++ b/docs/fsharp/language-reference/interfaces.md @@ -72,7 +72,7 @@ You can implement one or more interfaces in a class type by using the `interface Interface implementations are inherited, so any derived classes do not need to reimplement them. -## Implementing empty or marker interfaces +## Define empty or marker interfaces Empty interfaces, also known as marker interfaces, can be used to identify a set of types without requiring any specific behavior. These interfaces have no members and serve as a way to mark or tag types for categorization purposes.