User's Guide should mention that GADTSyntax applies to newtype declarations as well
Summary
The users' guide section on GADTSyntax
http://downloads.haskell.org/~ghc/latest/docs/html/users_guide/exts/gadt_syntax.html
contains plenty of examples, but only of data
declarations. Nowadays at least the same syntax can be used for newtype
declarations:
{-# Language GADTSyntax #-}
newtype Foo where
MkFoo :: Int -> Foo
Proposed improvements or changes
The use of GADTSyntax
with newtype
should be at least mentioned. Any additional constraints that apply only in this context should be clarified as well. For example a slight modification of this example
{-# Language GADTs #-}
newtype Foo a where
MkFoo :: Int -> Foo Int
triggers a compile error:
NewtypeGADT.hs:4:3: error:
• A newtype constructor must have a return type of form T a1 ... an
MkFoo :: Int -> Foo Int
• In the definition of data constructor ‘MkFoo’
In the newtype declaration for ‘Foo’
|
4 | MkFoo :: Int -> Foo Int
It seems that the GADTs
extension has no useful effect on newtype
declarations? That would make it easy to document.
Environment
- GHC version used (if appropriate): 9.2.1