Changes between Version 4 and Version 5 of PolymorphicComponents
 Timestamp:
 Dec 1, 2005 10:47:54 AM (9 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

PolymorphicComponents
v4 v5 6 6 == Brief Explanation == 7 7 8 Types of data constructor arguments are allowed local universal quantification (`forall`) and contexts constraining universally quantified type variables, e.g. 8 Data constructor arguments may have polymorphic types (marked with `forall`) 9 and contexts constraining universally quantified type variables, e.g. 9 10 {{{ 10 11 newtype Swizzle = MkSwizzle (forall a. Ord a => [a] > [a]) … … 14 15 MkSwizzle :: (forall a. Ord a => [a] > [a]) > Swizzle 15 16 }}} 17 This feature also makes it possible to create explicit dictionaries, e.g. 18 {{{ 19 data MyMonad m = MkMonad { 20 unit :: forall a. a > m a, 21 bind :: forall a b. m a > (a > m b) > m b 22 } 23 }}} 24 The field selectors here have ordinary polymorphic types: 25 {{{ 26 unit :: MyMonad m > a > m a 27 bind :: MyMonad m > m a > (a > m b) > m b 28 }}} 16 29 == References == 17 30 * [http://www.cse.ogi.edu/~mpj/pubs/haskwork95.html From HindleyMilner Types to FirstClass Structures] by Mark P. Jones, Haskell Workshop, 1995. 18 * ExistentialsVsPolymorphicComponents31 * distinguish from ExistentialQuantification 19 32 20 33 == Pros == 21 34 * type inference seems to be a simple extension of HindleyMilner. 22 35 * large increment in expressiveness: types become impredicative, albeit with an intervening data constructor, enabling Church encodings and similar System F tricks. 23 * used by the [http://www.haskell.org/ghc/docs/latest/html/libraries/base/TextParserCombinatorsReadP.html ReadP] type. 36 Functions with [wiki:Rank2Types rank2 types] may be trivially encoded. 37 Functions with [wiki:RankNTypes rankn types] may also be encoded, at the cost of packing and unpacking `newtype`s. 38 * used by the [http://www.haskell.org/ghc/docs/latest/html/libraries/base/TextParserCombinatorsReadP.html ReadP] type, which figures in a [wiki:ReadClass proposed replacement for the Read class]. 24 39 25 40 == Cons ==