Commit a972bddf authored by Simon Peyton Jones's avatar Simon Peyton Jones

Improve documentation of syntax for promoted lists

THe documentation in 7.9.4 of promoted list and tuple types was
misleading, which led to Trac #9882.  This patch makes explicit
that only type-level with two or more elements can have the
quote omitted.
parent 3f87866a
......@@ -1483,6 +1483,10 @@ atype :: { LHsType RdrName }
[mo $2,mc $4] }
| SIMPLEQUOTE var { sLL $1 $> $ HsTyVar $ unLoc $2 }
-- Two or more [ty, ty, ty] must be a promoted list type, just as
-- if you had written '[ty, ty, ty]
-- (One means a list type, zero means the list type constructor,
-- so you have to quote those.)
| '[' ctype ',' comma_types1 ']' {% ams (sLL $1 $> $ HsExplicitListTy
placeHolderKind ($2 : $4))
[mo $1, mj AnnComma $3,mc $5] }
......@@ -1503,11 +1507,11 @@ inst_types1 :: { [LHsType RdrName] }
| inst_type ',' inst_types1 {% addAnnotation (gl $1) AnnComma (gl $2)
>> return ($1 : $3) }
comma_types0 :: { [LHsType RdrName] }
comma_types0 :: { [LHsType RdrName] } -- Zero or more: ty,ty,ty
: comma_types1 { $1 }
| {- empty -} { [] }
comma_types1 :: { [LHsType RdrName] }
comma_types1 :: { [LHsType RdrName] } -- One or more: ty,ty,ty
: ctype { [$1] }
| ctype ',' comma_types1 {% addAnnotation (gl $1) AnnComma (gl $2)
>> return ($1 : $3) }
......
......@@ -6882,9 +6882,9 @@ is a single quote.</para>
</sect2>
<sect2 id="promoted-lists-and-tuples">
<title>Promoted lists and tuples types</title>
<title>Promoted list and tuple types</title>
<para>
Haskell's list and tuple types are natively promoted to kinds, and enjoy the
With <option>-XTypeOperators</option>, Haskell's list and tuple types are natively promoted to kinds, and enjoy the
same convenient syntax at the type level, albeit prefixed with a quote:
<programlisting>
data HList :: [*] -> * where
......@@ -6893,8 +6893,21 @@ data HList :: [*] -> * where
data Tuple :: (*,*) -> * where
Tuple :: a -> b -> Tuple '(a,b)
foo0 :: HList '[]
foo0 = HNil
foo1 :: HList '[Int]
foo1 = HCons (3::Int) HNil
foo2 :: HList [Int, Bool]
foo2 = ...
</programlisting>
Note that this requires <option>-XTypeOperators</option>.
For type-level lists of <emphasis>two or more elements</emphasis>,
such as the signature of <literal>foo2</literal> above, the quote may be omitted because the meaning is
umambiguous. But for lists of one or zero elements (as in <literal>foo0</literal>
and <literal>foo1</literal>), the quote is required, becuase the types <literal>[]</literal>
and <literal>[Int]</literal> have existing meanings in Haskell.
</para>
</sect2>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment