diff options
Diffstat (limited to 'docs/users_guide/exts')
-rw-r--r-- | docs/users_guide/exts/scoped_type_variables.rst | 2 | ||||
-rw-r--r-- | docs/users_guide/exts/static_pointers.rst | 12 | ||||
-rw-r--r-- | docs/users_guide/exts/type_applications.rst | 29 |
3 files changed, 12 insertions, 31 deletions
diff --git a/docs/users_guide/exts/scoped_type_variables.rst b/docs/users_guide/exts/scoped_type_variables.rst index d8a3885fa3..fa117fc032 100644 --- a/docs/users_guide/exts/scoped_type_variables.rst +++ b/docs/users_guide/exts/scoped_type_variables.rst @@ -263,7 +263,7 @@ Class and instance declarations :extension:`ScopedTypeVariables` allow the type variables bound by the top of a ``class`` or ``instance`` declaration to scope over the methods defined in the -``where`` part. Unlike :ref`decl-type-sigs`, type variables from class and +``where`` part. Unlike :ref:`decl-type-sigs`, type variables from class and instance declarations can be lexically scoped without an explicit ``forall`` (although you are allowed an explicit ``forall`` in an ``instance`` declaration; see :ref:`explicit-foralls`). For example: :: diff --git a/docs/users_guide/exts/static_pointers.rst b/docs/users_guide/exts/static_pointers.rst index e142b14be2..d6f5e55a73 100644 --- a/docs/users_guide/exts/static_pointers.rst +++ b/docs/users_guide/exts/static_pointers.rst @@ -51,18 +51,18 @@ All of the following are permissible: :: inc :: Int -> Int inc x = x + 1 - ref1 = static 1 + ref1 = static 'a' ref2 = static inc ref3 = static (inc 1) ref4 = static ((\x -> x + 1) (1 :: Int)) - ref5 y = static (let x = 1 in x) - ref6 y = let x = 1 in static x + ref5 = static (let x = 'a' in x) + ref6 = let x = 'a' in static x While the following definitions are rejected: :: ref7 y = let x = y in static x -- x is not closed ref8 y = static (let x = 1 in y) -- y is not let-bound - ref8 (y :: a) = let x = undefined :: a + ref9 (y :: a) = let x = undefined :: a in static x -- x has a non-closed type .. note:: @@ -99,7 +99,7 @@ expression is overloaded to allow lifting a ``StaticPtr`` into another type implicitly, via the ``IsStatic`` class: :: class IsStatic p where - fromStaticPtr :: StaticPtr a -> p a + fromStaticPtr :: Typeable a => StaticPtr a -> p a The only predefined instance is the obvious one that does nothing: :: @@ -111,7 +111,7 @@ See :base-ref:`GHC.StaticPtr.IsStatic`. Furthermore, type ``t`` is constrained to have a ``Typeable`` instance. The following are therefore illegal: :: - static show -- No Typeable instance for (Show a => a -> String) + static id -- No Typeable instance for (a -> a) static Control.Monad.ST.runST -- No Typeable instance for ((forall s. ST s a) -> a) That being said, with the appropriate use of wrapper datatypes, the diff --git a/docs/users_guide/exts/type_applications.rst b/docs/users_guide/exts/type_applications.rst index a459e1966d..00b33fe3fc 100644 --- a/docs/users_guide/exts/type_applications.rst +++ b/docs/users_guide/exts/type_applications.rst @@ -84,12 +84,12 @@ We can observe this behavior in a GHCi session: :: > :set -XTypeApplications -fprint-explicit-foralls > let myLength1 :: Foldable f => f a -> Int; myLength1 = length - > :type +v myLength1 + > :type myLength1 myLength1 :: forall (f :: * -> *) a. Foldable f => f a -> Int > let myLength2 = length - > :type +v myLength2 - myLength2 :: forall {a} {t :: * -> *}. Foldable t => t a -> Int - > :type +v myLength2 @[] + > :type myLength2 + myLength2 :: forall {t :: * -> *} {a}. Foldable t => t a -> Int + > :type myLength2 @[] <interactive>:1:1: error: • Cannot apply expression of type ‘t0 a0 -> Int’ @@ -97,30 +97,11 @@ We can observe this behavior in a GHCi session: :: • In the expression: myLength2 @[] Notice that since ``myLength1`` was defined with an explicit type signature, -:ghci-cmd:`:type +v` reports that all of its type variables are available +:ghci-cmd:`:type` reports that all of its type variables are available for type application. On the other hand, ``myLength2`` was not given a type signature. As a result, all of its type variables are surrounded with braces, and trying to use visible type application with ``myLength2`` fails. -Also note the use of :ghci-cmd:`:type +v` in the GHCi session above instead -of :ghci-cmd:`:type`. This is because :ghci-cmd:`:type` gives you the type -that would be inferred for a variable assigned to the expression provided -(that is, the type of ``x`` in ``let x = <expr>``). As we saw above with -``myLength2``, this type will have no variables available to visible type -application. On the other hand, :ghci-cmd:`:type +v` gives you the actual -type of the expression provided. To illustrate this: :: - - > :type myLength1 - myLength1 :: forall {a} {f :: * -> *}. Foldable f => f a -> Int - > :type myLength2 - myLength2 :: forall {a} {t :: * -> *}. Foldable t => t a -> Int - -Using :ghci-cmd:`:type` might lead one to conclude that none of the type -variables in ``myLength1``'s type signature are available for type -application. This isn't true, however! Be sure to use :ghci-cmd:`:type +v` -if you want the most accurate information with respect to visible type -application properties. - .. index:: single: ScopedSort |