Changes between Initial Version and Version 1 of PartialTypeAnnotations


Ignore:
Timestamp:
Feb 3, 2006 11:36:33 AM (9 years ago)
Author:
malcolm.wallace@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PartialTypeAnnotations

    v1 v1  
     1= Partial Type Signatures/Annotations = 
     2 
     3[[TicketQuery(description~=PartialTypeAnnotations)]] 
     4 
     5Short idea: _ in place of a type is "match anything" (by analogy to the wildcard pattern). This is /not/ the type (exists a.a), contrary to suggestions on the mailing list, as a) we wish to end up with a more specific type via inference and b) the existential type would have issues in a predicative type system (which includes the current rank-n implementations). Essentially, in checking the annotation we infer as normal for the _ and accept whatever is inferred. 
     6 
     7Note that _ *is not a type*. It's part of the type annotation, but should never be propagated "upwards" by the typechecker - only the type inferred for its position. 
     8 
     9There are some further possible extensions to this idea: 
     10 
     11 * Allow _ in class contexts to mean one or both of "and additional constraints" or "some type variable that will be inferred". Currently this isn't a well-developed idea, I haven't thought much about it - I like the idea of having a way to say "please don't fall over if I missed out a constraint" though. 
     12 * Allow "metavariables" (no longer actually meta due to being in the type system, of course) which might be written _a and appear multiple times in the same annotation always meaning the same type. 
     13 * Add some kind of binder for metavariables and give them lexical scope much as can be done with ordinary type variables. If we do this, top-level bindings would also make sense and allow us to name types we'd like inferred for us before using them as part of type declarations 
     14 * Allow some kind of constraints between metavariables (Frank Atanassow mentioned this to me on #haskell-blah) 
     15 
     16== Pros == 
     17 
     18 * Allows type annotations to convey information they need to without forcing the programmer to infer things the compiler should for them 
     19 * Can be used to get a complete type before filling in a permanent annotation 
     20 * Helps scale type annotations to cope with increasingly large types 
     21 * Metavariables provide similar readability benefits to type annotations while being more change-resistant due to inference 
     22 
     23== Cons == 
     24 
     25 * It's a new and untested feature 
     26 * It could encourage sloppy programming style 
     27 * Readability benefits are also untested