Skip to content

Remove awkward use of undefined from Generics usage example in docs

Summary

Location of documentation issue: GHC Generics docs

The docs for the GHC.Generics module include a nice little example of binary serialization for arbitrary Generic datatypes. As part of this example, an instance for V1 is introduced as follows:

-- The instance for 'V1' is slightly awkward (but also rarely used):
--
-- @
-- instance Encode' 'V1' where
--   encode' x = undefined
-- @
--
-- There are no values of type @V1 p@ to pass (except undefined), so this is actually impossible. ...

Somewhat confusingly, the undefined that occurs in the snippet is not the same as the one referred to in the comment. I think this would be a little less awkward if the documentation instead read...

Proposed improvements or changes

-- The instance for 'V1' is as follows (and requires the pragma @EmptyCase@):
--
-- @
-- instance Encode' 'V1' where
--   encode' x = case x of { }
-- @
--
-- There are no values of type @V1 p@ to pass, so it is impossible for this
-- function to be invoked. Thus we need no cases to handle the input. ...
Edited by Asad Saeeduddin
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information