Changes between Version 4 and Version 5 of PolymorphicComponents


Ignore:
Timestamp:
Dec 1, 2005 10:47:54 AM (10 years ago)
Author:
ross@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PolymorphicComponents

    v4 v5  
    66== Brief Explanation ==
    77
    8 Types of data constructor arguments are allowed local universal quantification (`forall`) and contexts constraining universally quantified type variables, e.g.
     8Data constructor arguments may have polymorphic types (marked with `forall`)
     9and contexts constraining universally quantified type variables, e.g.
    910{{{
    1011newtype Swizzle = MkSwizzle (forall a. Ord a => [a] -> [a])
     
    1415MkSwizzle :: (forall a. Ord a => [a] -> [a]) -> Swizzle
    1516}}}
     17This feature also makes it possible to create explicit dictionaries, e.g.
     18{{{
     19data MyMonad m = MkMonad {
     20    unit :: forall a. a -> m a,
     21    bind :: forall a b. m a -> (a -> m b) -> m b
     22  }
     23}}}
     24The field selectors here have ordinary polymorphic types:
     25{{{
     26unit :: MyMonad m -> a -> m a
     27bind :: MyMonad m -> m a -> (a -> m b) -> m b
     28}}}
    1629== References ==
    1730 * [http://www.cse.ogi.edu/~mpj/pubs/haskwork95.html From Hindley-Milner Types to First-Class Structures] by Mark P. Jones, Haskell Workshop, 1995.
    18  * ExistentialsVsPolymorphicComponents
     31 * distinguish from ExistentialQuantification
    1932
    2033== Pros ==
    2134 * type inference seems to be a simple extension of Hindley-Milner.
    2235 * 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/Text-ParserCombinators-ReadP.html ReadP] type.
     36   Functions with [wiki:Rank2Types rank-2 types] may be trivially encoded.
     37   Functions with [wiki:RankNTypes rank-n 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/Text-ParserCombinators-ReadP.html ReadP] type, which figures in a [wiki:ReadClass proposed replacement for the Read  class].
    2439
    2540== Cons ==