Changes between Version 28 and Version 29 of PolymorphicComponents
 Timestamp:
 Apr 4, 2007 10:00:10 PM (8 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

PolymorphicComponents
v28 v29 59 59 = Report TODO List = 60 60 List of items that need to change in the [http://darcs.haskell.org/haskellprimereport/report/haskellprimedraft.html draft report]. 61 1. Introduce a new ''special identifier'', '''forall'''. This identifier has a special interpretation in types and type schemes (i.e., it is ''not'' a type variable). 62 However, '''forall''' can still be used as an ordinary variable in expressions. 63 2. Syntax for writing type schemes: 64 (TODO: check for ambiguities with happy.) 61 62 == Syntax == 63 Introduce a new ''special identifier'', '''forall'''. This identifier has a special interpretation in types and type schemes (i.e., it is ''not'' a type variable). 64 However, '''forall''' can still be used as an ordinary variable in expressions. 65 66 Syntax for writing type schemes: 65 67 {{{ 66 68 poly > 'forall' tvar_1 ... tyvar_n '.' opt_ctxt type (n > 0) … … 71 73 bscheme > '(' poly ')'  btype 72 74 }}} 73 NOTE: Schemes should not contain quantified variables that are not mentioned 74 in the scheme body because this probably indicates a programmer error. 75 3.Syntax for '''data''' and '''newtype''' declarations75 NOTE: Schemes should not contain quantified variables that are not mentioned in the scheme body because this probably indicates a programmer error. 76 77 Syntax for '''data''' and '''newtype''' declarations 76 78 {{{ 77 79  Section 4.2.1 … … 89 91  con { var :: scheme } 90 92 }}} 91 92 93 NOTE: The grammar in the Haskell 98 report contains a minor bug that seems 94 to allow erroneous data declarations like the following: 93 95 {{{ 94 96 data T = C ! 95 97 }}} 96 For this reason I introduced the ''con_field'' productions. 97 4. Labeled fields. 98 1. Type of the selector functions: 98 For this reason I introduced the ''con_field'' productions. 99 100 == Working with datatypes == 101 102 === Labeled fields === 103 104 Type of the selector functions: 99 105 {{{ 100 106 data T a = C { x :: forall b. ctxt => type } 101 107 x :: ctxt => T a > type 102 108 }}} 103 2. If different constructors of the same datatype contain the same label,104 then the corresponding schemes should be equal up to renaming of the105 quantified variables.106 109 110 If different constructors of the same datatype contain the same label, 111 then the corresponding schemes should be equal up to renaming of the 112 quantified variables. This ensures that we can give a reasonable type 113 for the selector functions. 114 115 === Constructors === 116 117 Constructors that have polymorphic components cannot appear in the program 118 without values for their polymorphic fields. For example, 119 consider the following declaration: 120 {{{ 121 data T a = C Int (forall b. b > a) a 122 }}} 123 The constructor function 'C' cannot be used with less then two arguments 124 because the second argument is the last polymorphic component of 'C'. 125 Here are some examples that illustrate what we can and cannot do with 'C': 126 {{{ 127 ex1 :: a > T a 128 ex1 a = C 2 (const a)  ok. 129 130 ex2 = C 2  not ok, needs another argument. 131 }}} 132 This restriction ensures that all expressions in the program have 133 ordinary HindleyMilner types. 134 135 The values for the polymorphic components should have type schemes 136 that are at least as polymorphic as what is declared in the datatype. 137 This is checked is similar to the check that is performed when an 138 expression has an explicit type signature. 107 139 108 140 TODO: … … 110 142 1. english text in Labelled fields  give an example of fields with polymorphic types, or do this in section 3? 111 143 1. anything in "kind inference"? 112 1. ''note for'': for field labels, when you have the same label in different constructors, it's permitted as long as the type is the same; anything here to describe the syntactic checking that occurs to determine whether these types are the same? "Syntactic upto alpharenaming." Might be unintuative as this is rejected by GHC and Hugs:113 {{{114 data T = C1 { x :: forall a. (Show a,Eq a) => a > a }115  C2 { x :: forall a. (Eq a,Show a) => a > a }116 }}}117 144 1. ''note'' you can name polymorphic components (see design choice above) 118 145 1. when you match on ''x'' it instantiates the forall to a monomorphic type as below: