[Git][ghc/ghc][master] docs: Update mention of ($) type in user guide
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Tue Jun 18 22:52:40 UTC 2024
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
1eb15c61 by Jakob Bruenker at 2024-06-18T18:51:04-04:00
docs: Update mention of ($) type in user guide
Fixes #24909
- - - - -
1 changed file:
- docs/users_guide/exts/representation_polymorphism.rst
Changes:
=====================================
docs/users_guide/exts/representation_polymorphism.rst
=====================================
@@ -79,14 +79,26 @@ representation-polymorphic type.
However, not all is lost. We can still do this: ::
- ($) :: forall r (a :: Type) (b :: TYPE r).
+ good :: forall r (a :: Type) (b :: TYPE r).
(a -> b) -> a -> b
- f $ x = f x
+ good f x = f x
Here, only ``b`` is representation-polymorphic. There are no variables
with a representation-polymorphic type. And the code generator has no
-trouble with this. Indeed, this is the true type of GHC's ``$`` operator,
-slightly more general than the Haskell 98 version.
+trouble with this. Nonetheless, there is a way to write a definition with
+``bad``'s type: ::
+
+
+ ($) :: forall (r1 :: RuntimeRep) (r2 :: RuntimeRep)
+ (a :: TYPE r1) (b :: TYPE r2).
+ (a -> b) -> a -> b
+ ($) f = f
+
+By eta-reducing, we got rid of ``x``, and thus have no variable with a
+representation-polymorphic type. Indeed, this is the true type of GHC's ``$``
+operator, slightly more general than the Haskell 98 version. However, its
+strictness properties are different: ``(good undefined) `seq` ()`` is equivalent
+to ``()``, whereas ``(($) undefined) `seq` ()`` diverges.
Because the code generator must store and move arguments as well
as variables, the logic above applies equally well to function arguments,
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1eb15c61652ac70829b2130526e729e8177bbeb5
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1eb15c61652ac70829b2130526e729e8177bbeb5
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/20240618/89221e2e/attachment-0001.html>
More information about the ghc-commits
mailing list