-
Notifications
You must be signed in to change notification settings - Fork 832
Description
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
- Not using a signature file
suggested by one of the commenters, who also wondered whether the signature file feature is unofficially deprecated - true?
- 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
- 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
- ? - 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