You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
The text was updated successfully, but these errors were encountered:
Firstly, welcome to F# and I hope you have a great time :)
Your best options are 2 and 3. An abstract type definition that is made concrete in the implementation like this just isn't supported in interface files. You need an explicit signature either via the type definition or inline on the exception type.
It likely won't ever be supported, since the F# design is just one where you have explicit signatures in signature files. Being able to swap out an implementation for an entirely abstract type just isn't a goal in the language.
I suppose the compiler error could be made more clear - we'd be happy to take a look at a PR that improves it, but we're unlikely to do it ourselves since the scenario is fairly niche.
Repro steps
Consider this signature file, Test.fsi:
With this implementation file, Test.fs:
Expected behavior
The program compiles
Actual behavior
Compiler error:
Known workarounds
Originally asked on StackOverflow
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
The text was updated successfully, but these errors were encountered: