RFC: -Wsevere – erroring warnings

The GHC Steering Committee is currently debating whether -Werror=missing-methods -Werror=missing-fields should be enabled by default. Please let us know what you think!

3 Likes

I’ll share my specific case.
I have a library called posit, it implements Enum but not the toEnum and fromEnum functions, because of the statement in the documentation:

It is implementation-dependent what fromEnum returns when applied to a value that is too large to fit in an Int.

I’m not sure about the origin of the to/fromEnum functions, perhaps they were added for convince. I believe that prelude would be better if to/fromEnum wasn’t restricted to a very small type like Int. Perhaps that could be improved in the future with the forall -> visibility stuff that’s in the works.

I believe ideally, I would like the consumer of my library to have a compile error if they try and use the to/fromEnum function because they are not implemented, but they could still compile the lib and use the better pred and succ functions.

I’m open to suggestions, if there is a better way to handle this case.

Very generally: Better than not implementing these methods (for whatever reason) is to implement them with an explicit error "reason why it’s not implemented" definition. It doesn’t give compile time errors when they are used downstream, but at least a more helpful run-time warnings. (And your library would still compile under -Werror=missing=methods).

2 Likes

I did a quick test and for ghci and a program compiled with ghc, gives a runtime error that states:
No instance nor default method for class operation fromEnum
But if I run the same test with a stack test it just says ERROR.

I will update with the explicit error, in the next release of my library.

Thanks,

So, perhaps we could update prelude with default errors for missing to/fromEnum, like this:

fromEnum _ = error “Please do not use ‘enumFrom’, it is size limited to Int, and can be machine dependent. Please advocate for the function to be size polymorphic of a FixedWidthInteger.”
toEnum _ = error “Please do not use ‘enumTo’, it is size limited to Int, and can be machine dependent. Please advocate for the function to be size polymorphic of a FixedWidthInteger.”

Of course the definition of FixedWidthInteger is:

type FixedWidthInteger a =
(Bits a
,Bounded a
,Enum a
,Integral a
,Eq a
,Ord a
,Num a
,Read a
,Show a
,Storable a
,Uniform a
)

and good use of data-dword, TypeFamilies, DataKinds, CPP, and other fine extensions.

The default type can even be Int.

I’m open to suggestions, if there is a better way to handle this case.

My suggestion, or at least what I’d do myself, is just not implement Enum.