[Git][ghc/ghc][wip/jakobbruenker/T24909] docs: Update mention of ($) type in user guide
Jakob Brünker (@JakobBruenker)
gitlab at gitlab.haskell.org
Thu Jun 6 03:15:51 UTC 2024
Jakob Brünker pushed to branch wip/jakobbruenker/T24909 at Glasgow Haskell Compiler / GHC
Commits:
5d55f178 by Jakob Bruenker at 2024-06-06T05:14:44+02: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/5d55f178e9e35ac78307e6be8a0021f221f253f3
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5d55f178e9e35ac78307e6be8a0021f221f253f3
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/20240605/8173551e/attachment-0001.html>
More information about the ghc-commits
mailing list