sdgfsdh
sdgfsdh

Reputation: 37045

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

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.


dotnet --version
3.1.403

Upvotes: 4

Views: 349

Answers (1)

Jim Foye
Jim Foye

Reputation: 2036

[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.

Upvotes: 8

Related Questions