Skip to content

Signature files are incompatible with an abstract exception record containing a function field #10520

@2BitSalute

Description

@2BitSalute

Repro steps

Consider this signature file, Test.fsi:

module Test
type exception_type
exception TestException of exception_type
val throw_test_exception: unit -> unit

With this implementation file, Test.fs:

module Test
type exception_type = { value: unit -> unit }
exception TestException of exception_type
let throw_test_exception (): unit =
    let r = { value = (fun () -> ()) }
    raise (TestException r)

Expected behavior

The program compiles

Actual behavior

Compiler error:

The type definitions for type 'exception_type' in the signature and implementation are not compatible because the signature requires that the type supports the interface System.Collections.IStructuralEquatable but the interface has not been implemented

Known workarounds

Originally asked on StackOverflow

  1. Not using a signature file

    suggested by one of the commenters, who also wondered whether the signature file feature is unofficially deprecated - true?

  2. Excluding the function-typed field from the exception record

    this is what I did in my actual code - I originally ended up with this compiler error because I lazily typed my exception with the module's main type, which happened to contain a function field

  3. Making the record type concrete, rather than abstract

    suggested by the answer to my SO question; this somewhat defeats the purpose of using a signature file

  4. ? - some way to "support the interface IStructuralEquatable"?

    My sense now is that this can't be done in "user land" - accurate?

Context: I'm coming to F# from OCaml, where signature files and abstract types are widely used, so I'm very hesitant to accept #1 or #3

Related information

  • Operating system: Windows 10
  • .NET Runtime kind: .NET Core
  • Editing Tools: Visual Studio Code

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions