Make it difficult to misuse `Show`
Clarification and motivation
Periodically it still happens that someone uses show
instead of build
, and that bug is handled only later.
-
Someone may just forget to use
build
-
Type of a thing may change, and type system does not enforce us to change
show
usages tobuild
.Recent example:
show (typeRep @a)
is good (TypeRep
has neatShow
instance), but being changed toshow (demote @a)
this is not so good anymore.Another example: I could have
newtype MyType = MyType Int deriving newtype (Show)
, and later add some field to it. Again, beforeshow @MyType
was ok, but after a field is added - not so ok.
I think the type system should handle such cases and make the use of show
harder.
For instance, we can make Show
instance require an explicit permission to be used:
type DebugOutput = Given DebugOutputAllowed
data DebugOutputAllowed
allowDebugOutput :: (DebugOutput => a) -> a
---
data MyType = ...
deriving stock instance DebugOutput => Show MyType
The main cons here - Show
instances become quite verbose.
Acceptance criteria
- I cannot misuse
show
instead ofbuild
for our custom morley types,show
requires an explicit permission to be used.