Changes between Version 16 and Version 17 of ScopedTypeVariables


Ignore:
Timestamp:
Jan 31, 2006 1:29:50 PM (8 years ago)
Author:
ross@…
Comment:

class & instance examples

Legend:

Unmodified
Added
Removed
Modified
  • ScopedTypeVariables

    v16 v17  
    1313Quantification of type variables over expressions is needed. 
    1414 
     15== References == 
     16 * [http://www.haskell.org/ghc/docs/latest/html/users_guide/type-extensions.html#scoped-type-variables GHC documentation] and [http://www.haskell.org/pipermail/glasgow-haskell-users/2006-January/009565.html a recent revision] 
     17 * [http://cvs.haskell.org/Hugs/pages/users_guide/type-annotations.html Hugs documentation] 
     18 
     19Note that although GHC and Hugs use the same syntax, the meaning of type variables is quite different, and there are other differences too. 
     20 
     21== Tickets == 
     22[[TicketQuery(description~=ScopedTypeVariables)]] 
     23 
     24== Binding sites for type variables == 
     25 
     26=== Class and instance declarations === 
     27 
    1528Haskell already binds type variables in class and instance declarations. 
    16 It makes sense for these to also scope over bindings in the `where` part, but currently only GHC implements this. 
     29It is proposed that these also scope over bindings in the `where` part (as currently implemented by GHC, but not Hugs). 
     30This permits signatures that would not otherwise be possible. 
     31 
     32An example of a class declaration: 
     33{{{ 
     34class C a where 
     35    op :: [a] -> a 
     36 
     37    op xs = let ys :: [a] 
     38                ys = reverse xs 
     39            in head ys 
     40}}} 
     41An example of an instance declaration: 
     42{{{ 
     43class C t where 
     44    op :: t -> t 
     45 
     46instance C [a] where 
     47    op xs = let ys :: [a] 
     48                ys = reverse xs 
     49            in ys ++ ys 
     50}}} 
     51 
     52=== Type annotations === 
    1753 
    1854GHC provides three extensions that bind type variables: 
     
    4783Hugs supports only pattern type signatures, with rigid type variables. 
    4884 
    49 == References == 
    50  * [http://www.haskell.org/ghc/docs/latest/html/users_guide/type-extensions.html#scoped-type-variables GHC documentation] and [http://www.haskell.org/pipermail/glasgow-haskell-users/2006-January/009565.html a recent revision] 
    51  * [http://cvs.haskell.org/Hugs/pages/users_guide/type-annotations.html Hugs documentation] 
    52  
    53 Note that although GHC and Hugs use the same syntax, the meaning of type variables is quite different, and there are other differences too. 
    54  
    55 == Tickets == 
    56 [[TicketQuery(description~=ScopedTypeVariables)]] 
    57  
    5885== Pros == 
    5986  * Allows better documentation (without them, some expressions cannot be annotated with their types). 
     
    77104    A rule like ExplicitQuantification might be needed if these were put into the standard. 
    78105  
    79 == Proposal 1 == 
     106== Alternative proposal 1 == 
    80107 
    81108Both let-bound and lambda-bound type variables are in scope in the 
     
    94121(perhaps this text can be cleaned up further? what is a better term for expression type signature?) 
    95122 
    96 == Proposal 2 == 
     123== Alternative proposal 2 == 
    97124 
    98125Restrict the above extensions to: