Home » F# Signature

F# Signatures

In F#, signature file contains information about the public signatures. Signatures can be of a set of program elements, such as types, namespaces, and modules. It can be used to specify the accessibility of these program elements.

For each code in F# you can have signature file. This file has the same name as the code file but with the extension .fsi instead of .fs

There are some rules of signature:

  1. Type abbreviations in an implementation file must not match a type without an abbreviation in a signature file.
  2. Records and discriminated unions must expose either all or none of their fields and constructors. Classes can reveal some, all, or none of their fields and methods in the signature.
  3. Interface types must reveal all their methods and interfaces.
  4. Modifiers for accessibility (public, internal, and private) and the inline and mutable modifiers in the signature must match those in the implementation.
  5. The number of generic type parameters (either implicitly inferred or explicitly declared) must match, and the types and type constraints in generic type parameters must match.
  6. If the Literal attribute is used, it must appear in both the signature and the implementation, and the same literal value must be used for both.
  7. The pattern of parameters (also known as the arity) of signatures and implementations must be consistent.

F# Signature file Example

This is code file named signature.fs

This, is signature file named signature.fsi

As you can see this file neither implement code nor has business logic. It just provide information about code file in abstract form.

You may also like