[Git][ghc/ghc][master] Add Note about why we need forall in Code to be on the right

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Wed Jul 5 02:10:14 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
cf735db8 by Andrei Borzenkov at 2023-07-04T22:09:51-04:00
Add Note about why we need forall in Code to be on the right

- - - - -


1 changed file:

- libraries/template-haskell/Language/Haskell/TH/Syntax.hs


Changes:

=====================================
libraries/template-haskell/Language/Haskell/TH/Syntax.hs
=====================================
@@ -380,8 +380,7 @@ The splice will evaluate to (MkAge 3) and you can't add that to
 -- Code constructor
 #if __GLASGOW_HASKELL__ >= 909
 type Code :: (Kind.Type -> Kind.Type) -> forall r. TYPE r -> Kind.Type
-  -- The nested `forall` makes it possible to assign the arity of 0 to
-  --   type CodeQ = Code Q
+  -- See Note [Foralls to the right in Code]
 #else
 type Code :: (Kind.Type -> Kind.Type) -> TYPE r -> Kind.Type
 #endif
@@ -424,6 +423,23 @@ newtype Code m a = Code
 --       In the Template Haskell splice $$([|| "foo" ||])
 
 
+{- Note [Foralls to the right in Code]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Code has the following type signature:
+   type Code :: (Kind.Type -> Kind.Type) -> forall r. TYPE r -> Kind.Type
+
+This allows us to write
+   data T (f :: forall r . (TYPE r) -> Type) = MkT (f Int) (f Int#)
+
+   tcodeq :: T (Code Q)
+   tcodeq = MkT [||5||] [||5#||]
+
+If we used the slightly more straightforward signature
+   type Code :: foral r. (Kind.Type -> Kind.Type) -> TYPE r -> Kind.Type
+
+then the example above would become ill-typed.  (See #23592 for some discussion.)
+-}
+
 -- | Unsafely convert an untyped code representation into a typed code
 -- representation.
 unsafeCodeCoerce :: forall (r :: RuntimeRep) (a :: TYPE r) m .



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cf735db883b2ff83e61f9848a39f1066d3288a43

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cf735db883b2ff83e61f9848a39f1066d3288a43
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230704/ea6c087a/attachment-0001.html>


More information about the ghc-commits mailing list