Mike Henderson
Mike Henderson

Reputation: 1317

Unable to use inheritance with multiple files in f#

I am having trouble with what seems to be a trivial use of inheritance in an f# project.

File 1:

namespace MercurySchool.Models

[<AbstractClass>]
type Resource() =   

    abstract member  Href: string with get, set
    abstract member  Method: string with get, set
    abstract member  Relations: string[] with get, set
    abstract member  Id: int with get, set
    abstract member  Name: string with get, set
    abstract member  Description: string with get, set

File 2:

namespace MercurySchool.Models

type School() =
    inherit Resource()

In File 2 I am getting the following errors:

Feels like there's a simple resolution, but so far it escapes me.

Some background:

Upvotes: 1

Views: 83

Answers (1)

Mike Henderson
Mike Henderson

Reputation: 1317

The problem indeed appears to be the order of compilation, as Fydor suggested.

I changed the fsdprog file from this:

  <ItemGroup>
    <Compile Include="Models\*.fs" />
    <Compile Include="Program.fs" />
  </ItemGroup>

to a more explicit declaration:

  <ItemGroup>
    <Compile Include="Models\Resource.fs" />
    <Compile Include="Models\school.fs" />
    <Compile Include="Program.fs" />
  </ItemGroup>

After a few other changes unrelated to this question, the project builds.

Upvotes: 1

Related Questions