Avoiding the error where a module and a type definition occur in two parts of an assembly

Viewed 163

Suppose I have a project like this:

// Types.fs

namespace App

type Foo =
  {
    X : int
  }
// Foo.fs

module App.Foo

let doubleIt (foo : Foo) =
  {
    X = foo.X * 2
  }

Then I get an error like this:

Types.fs(3,6): error FS0250: A module and a type definition named 'Foo' occur in namespace 'App' in two parts of this assembly

However, if I put everything in one file it works:

// Everything.fs

namespace App

type Foo =
  {
    X : int
  }

module Foo =

  let doubleIt (foo : Foo) =
    {
      X = foo.X * 2
    }

But to me these seem like the same thing; and I don't want to organize everything into one big file.

  • What's going on here?
  • Why can't I put the module into another file?
  • What is an idiomatic way to organize this code?

dotnet --version
3.1.403
1 Answers

[FS0250] - 'ModuleSuffix' needs to be added explicitly

So, if you want to keep the type and module in separate files, then decorate the module name with

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]

If you place them in the same file, that gets done for you.

Related