1. 20 Feb, 2003 2 commits
    • simonpj's avatar
      [project @ 2003-02-20 18:33:50 by simonpj] · 56b5a8b8
      simonpj authored
      -------------------------------------
            Add Core Notes and the {-# CORE #-} pragma
      	-------------------------------------
      
      This is an idea of Hal Daume's. The key point is that Notes in Core
      are augmented thus:
      
        data Note
          = SCC CostCentre
          | ...
          | CoreNote String     -- NEW
      
      These notes can be injected via a Haskell-source pragma:
      
         f x = ({-# CORE "foo" #-} show) ({-# CORE "bar" #-} x)
      
      This wraps a (Note (CoreNote "foo")) around the 'show' variable,
      and a similar note around the argument to 'show'.
      
      These notes are basically ignored by GHC, but are emitted into
      External Core, where they may convey useful information.
      
      Exactly how code involving these notes is munged by the simplifier
      isn't very well defined.  We'll see how it pans out.  Meanwhile
      the impact on the rest of the compiler is minimal.
      56b5a8b8
    • simonpj's avatar
      [project @ 2003-02-20 13:23:47 by simonpj] · 00227c6a
      simonpj authored
      -------------------------------------
      	   Complete an earlier TH commit
      	-------------------------------------
      
      In this earlier commit:
      
        3.  Ensure that a declaration quotation [d| ... |] does not have a
            permanent effect on the instance environment. (A TH fix.)
      
      I had forgotten to do a stage2 compile.  This commit just completes
      the earlier work.  I moved some code from TcExpr (long) to TcSplice
      (shorter) which had the happy effect of bringing related code together.
      00227c6a
  2. 19 Feb, 2003 1 commit
    • simonpj's avatar
      [project @ 2003-02-19 15:54:05 by simonpj] · 3355c9d5
      simonpj authored
      -------------------------------------
      	 	Two minor wibbles
      	-------------------------------------
      
      
      1.  Make the generic toT/fromT Ids for "generic derived classes" into
          proper ImplicitIds, with their own GlobalIdDetails. This makes it
          easier to identify them.  (The lack of this showed up as a bug
          when I made an apparently-innocuous other change.)
      
      2.  Distinguish ClassOpIds from RecordSelIds in their GlobalIdDetails.
          They are treated differently here and there, so I made this change
          as part of (1)
      
      3.  Ensure that a declaration quotation [d| ... |] does not have a
          permanent effect on the instance environment. (A TH fix.)
      3355c9d5
  3. 18 Feb, 2003 1 commit
    • simonpj's avatar
      [project @ 2003-02-18 15:54:19 by simonpj] · b979d0f2
      simonpj authored
      -------------------------------------
      	 	Two minor wibbles
      	-------------------------------------
      
      [These two unrelated fixes just got tangled together in my tree.]
      
      1.  Fix a crash when a class op is used as a record selector
      
      2.  Fix a wibble related to the new DataCon naming story.
          In tcId, treat the DataCon case entirely separately, because
          its "stupid context" doesn't show up in its type.
      
          On the way, remove the DataCon cases in tcLookupId and tcLookupGlobalId
          The should not be necessary.  He says hopefully.
      b979d0f2
  4. 05 Feb, 2003 1 commit
  5. 13 Jan, 2003 1 commit
    • simonpj's avatar
      [project @ 2003-01-13 17:01:22 by simonpj] · 0877011a
      simonpj authored
      ------------------------------------
      	(a) Improve reporting of staging errors
      	(b) Tidy up the construction of dict funs
      			and default methods
      	------------------------------------
      0877011a
  6. 06 Jan, 2003 1 commit
    • simonpj's avatar
      [project @ 2003-01-06 15:30:14 by simonpj] · fcf37c94
      simonpj authored
      --------------------------------------------------------------
      	Several small but tiresome things shown up by Template Haskell
      	--------------------------------------------------------------
      
      1. Make the 'knot' in TcRnDriver much smaller; in fact move it to
         TcIfaceSig.tcInterfaceSigs.  Reasons
      	a) much tidier
      	b) avoids a loop in Template Haskell, when we try to run
      	   an expression during type checking (when the knot is
      	   not fully tied)
      
         See comments in TcIfaceSig
      
      2. Stop typechecking if tcGroup fails.  Reason: otherwise tcLookup can
         fail in the next group.
      
      3. Catch linking errors more gracefully when running a splice (in TcSplice)
      fcf37c94
  7. 04 Nov, 2002 1 commit
  8. 25 Oct, 2002 1 commit
  9. 23 Oct, 2002 2 commits
    • simonpj's avatar
      [project @ 2002-10-23 14:30:00 by simonpj] · 203a687f
      simonpj authored
      ------------------------------------------------
      	Allow implicit-parameter bindings anywhere that
      		a normal binding group is allowed.
      	------------------------------------------------
      
      That is, you can have implicit parameters
      
      	* in a let binding
      	* in a where clause (but then you can't have non-implicit
      	  ones as well)
      	* in a let group in a list comprehension or monad do-notation
      
      The implementation is simple: just add IPBinds to the allowable forms of HsBinds,
      and remove the HsWith expression form altogether.   (It now comes in via the
      HsLet form.)
      
      It'a a nice generalisation really.  Needs a bit of documentation, which I'll do next.
      203a687f
    • chak's avatar
      [project @ 2002-10-23 02:36:37 by chak] · 6aa5e648
      chak authored
      Added an import to make TH compile.
      6aa5e648
  10. 22 Oct, 2002 1 commit
  11. 18 Oct, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-10-18 13:41:50 by simonpj] · f53483a2
      simonpj authored
      --------------------------------
         Fix a serious error in the "newtype deriving" feature
      	--------------------------------
      
      The "newtype deriving" feature lets you derive arbitrary classes for
      a newtype, not just the built-in ones (Read, Show, Ix etc).  It's very
      cool, but Hal Duame discovered that it did utterly the Wrong Thing
      for superclasses.  E.g.
      
      	newtype Foo = MkFoo Int deriving( Show, Num, Eq )
      
      You'd get a Num instance for Foo that was *identical* to the
      Num instance for Int, *including* the Show superclass. So the
      superclass in the Num dictionary would show a Foo just like an
      Int, which is wrong... it should show as "Foo n".
      
      This commit fixes the problem, by building a new dictionary every time,
      but using the methods from the dictionary for the representation type.
      
      I also fixed a bug that prevented it working altogether when the
      representation type was not the application of a type constructor.
      For example, this now works
      
      	newtype Foo a = MkFoo a deriving( Num, Eq, Show )
      
      
      I also made it a bit more efficient in the case where the type is
      not parameterised.  Then the "dfun" doesn't need to be a function.
      f53483a2
  12. 11 Oct, 2002 2 commits
    • simonpj's avatar
      [project @ 2002-10-11 16:45:16 by simonpj] · 37f72280
      simonpj authored
      More reification wibbling; and -ddump-splices
      37f72280
    • simonpj's avatar
      [project @ 2002-10-11 14:46:02 by simonpj] · cbb5beb0
      simonpj authored
      ------------------------------------------
      	Implement reification for Template Haskell
      	------------------------------------------
      
      This is entirely un-tested, but I don't think it'll break non-TH stuff.
      
      Implements
      	reifyDecl T :: Dec	-- Data type T
      	reifyDecl C :: Dec	-- Class C
      	reifyType f :: Typ	-- Function f
      
      I hope.
      cbb5beb0
  13. 09 Oct, 2002 3 commits
  14. 27 Sep, 2002 1 commit
  15. 26 Sep, 2002 1 commit
  16. 13 Sep, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-09-13 15:02:25 by simonpj] · 9af77fa4
      simonpj authored
      --------------------------------------
      	Make Template Haskell into the HEAD
      	--------------------------------------
      
      This massive commit transfers to the HEAD all the stuff that
      Simon and Tim have been doing on Template Haskell.  The
      meta-haskell-branch is no more!
      
      WARNING: make sure that you
      
        * Update your links if you are using link trees.
          Some modules have been added, some have gone away.
      
        * Do 'make clean' in all library trees.
          The interface file format has changed, and you can
          get strange panics (sadly) if GHC tries to read old interface files:
          e.g.  ghc-5.05: panic! (the `impossible' happened, GHC version 5.05):
      	  Binary.get(TyClDecl): ForeignType
      
        * You need to recompile the rts too; Linker.c has changed
      
      
      However the libraries are almost unaltered; just a tiny change in
      Base, and to the exports in Prelude.
      
      
      NOTE: so far as TH itself is concerned, expression splices work
      fine, but declaration splices are not complete.
      
      
      		---------------
      		The main change
      		---------------
      
      The main structural change: renaming and typechecking have to be
      interleaved, because we can't rename stuff after a declaration splice
      until after we've typechecked the stuff before (and the splice
      itself).
      
      * Combine the renamer and typecheker monads into one
      	(TcRnMonad, TcRnTypes)
        These two replace TcMonad and RnMonad
      
      * Give them a single 'driver' (TcRnDriver).  This driver
        replaces TcModule.lhs and Rename.lhs
      
      * The haskell-src library package has a module
      	Language/Haskell/THSyntax
        which defines the Haskell data type seen by the TH programmer.
      
      * New modules:
      	hsSyn/Convert.hs 	converts THSyntax -> HsSyn
      	deSugar/DsMeta.hs 	converts HsSyn -> THSyntax
      
      * New module typecheck/TcSplice type-checks Template Haskell splices.
      
      		-------------
      		Linking stuff
      		-------------
      
      * ByteCodeLink has been split into
      	ByteCodeLink	(which links)
      	ByteCodeAsm	(which assembles)
      
      * New module ghci/ObjLink is the object-code linker.
      
      * compMan/CmLink is removed entirely (was out of place)
        Ditto CmTypes (which was tiny)
      
      * Linker.c initialises the linker when it is first used (no need to call
        initLinker any more).  Template Haskell makes it harder to know when
        and whether to initialise the linker.
      
      
      	-------------------------------------
      	Gathering the LIE in the type checker
      	-------------------------------------
      
      * Instead of explicitly gathering constraints in the LIE
      	tcExpr :: RenamedExpr -> TcM (TypecheckedExpr, LIE)
        we now dump the constraints into a mutable varabiable carried
        by the monad, so we get
      	tcExpr :: RenamedExpr -> TcM TypecheckedExpr
      
        Much less clutter in the code, and more efficient too.
        (Originally suggested by Mark Shields.)
      
      
      		-----------------
      		Remove "SysNames"
      		-----------------
      
      Because the renamer and the type checker were entirely separate,
      we had to carry some rather tiresome implicit binders (or "SysNames")
      along inside some of the HsDecl data structures.  They were both
      tiresome and fragile.
      
      Now that the typechecker and renamer are more intimately coupled,
      we can eliminate SysNames (well, mostly... default methods still
      carry something similar).
      
      		-------------
      		Clean up HsPat
      		-------------
      
      One big clean up is this: instead of having two HsPat types (InPat and
      OutPat), they are now combined into one.  This is more consistent with
      the way that HsExpr etc is handled; there are some 'Out' constructors
      for the type checker output.
      
      So:
      	HsPat.InPat	--> HsPat.Pat
      	HsPat.OutPat	--> HsPat.Pat
      	No 'pat' type parameter in HsExpr, HsBinds, etc
      
      	Constructor patterns are nicer now: they use
      		HsPat.HsConDetails
      	for the three cases of constructor patterns:
      		prefix, infix, and record-bindings
      
      	The *same* data type HsConDetails is used in the type
      	declaration of the data type (HsDecls.TyData)
      
      Lots of associated clean-up operations here and there.  Less code.
      Everything is wonderful.
      9af77fa4
  17. 01 Aug, 2002 1 commit
  18. 29 Jul, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-07-29 12:22:37 by simonpj] · 2ddea0a8
      simonpj authored
      *** MERGE TO STABLE BRANCH ***
      
      
      Surprisingly large delta to make rebindable names work properly.
      I was sloppily not checking the type of the user-supplied name,
      and Ashley Yakeley's first experiment showed up the problem!
      
      Solution: typechecker has to check both the 'standard' name and
      the 'user' name and check the latter has a type compatible with the
      former.
      
      The main comment is with Inst.tcSyntaxName (a new function).
      2ddea0a8
  19. 09 Jul, 2002 1 commit
  20. 05 Jun, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-06-05 14:39:27 by simonpj] · b2f644fa
      simonpj authored
      ---------------------------------------
      	Add rebindable syntax for do-notation
      		(this time, on the HEAD)
      	---------------------------------------
      
      Make do-notation use rebindable syntax, so that -fno-implicit-prelude
      makes do-notation use whatever (>>=), (>>), return, fail are in scope,
      rather than the Prelude versions.
      
      On the way, combine HsDo and HsDoOut into one constructor in HsSyn,
      and tidy up type checking of HsDo.
      b2f644fa
  21. 23 May, 2002 1 commit
  22. 29 Apr, 2002 1 commit
    • simonmar's avatar
      [project @ 2002-04-29 14:03:38 by simonmar] · b085ee40
      simonmar authored
      FastString cleanup, stage 1.
      
      The FastString type is no longer a mixture of hashed strings and
      literal strings, it contains hashed strings only with O(1) comparison
      (except for UnicodeStr, but that will also go away in due course).  To
      create a literal instance of FastString, use FSLIT("..").
      
      By far the most common use of the old literal version of FastString
      was in the pattern
      
      	  ptext SLIT("...")
      
      this combination still works, although it doesn't go via FastString
      any more.  The next stage will be to remove the need to use this
      special combination at all, using a RULE.
      
      To convert a FastString into an SDoc, now use 'ftext' instead of
      'ptext'.
      
      I've also removed all the FAST_STRING related macros from HsVersions.h
      except for SLIT and FSLIT, just use the relevant functions from
      FastString instead.
      b085ee40
  23. 11 Apr, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-04-11 12:03:29 by simonpj] · a7b95beb
      simonpj authored
      -------------------
      	Mainly derived Read
      	-------------------
      
      This commit is a tangle of several things that somehow got wound up
      together, I'm afraid.
      
      
      The main course
      ~~~~~~~~~~~~~~~
      Replace the derived-Read machinery with Koen's cunning new parser
      combinator library.   The result should be
      	* much smaller code sizes from derived Read
      	* faster execution of derived Read
      
      WARNING: I have not thoroughly tested this stuff; I'd be glad if you did!
      	 All the hard work is done, but there may be a few nits.
      
      The Read class gets two new methods, not exposed
      in the H98 inteface of course:
        class Read a where
          readsPrec    :: Int -> ReadS a
          readList     :: ReadS [a]
          readPrec     :: ReadPrec a		-- NEW
          readListPrec :: ReadPrec [a]	-- NEW
      
      There are the following new libraries:
      
        Text.ParserCombinators.ReadP		Koens combinator parser
        Text.ParserCombinators.ReadPrec	Ditto, but with precedences
      
        Text.Read.Lex				An emasculated lexical analyser
      					that provides the functionality
      					of H98 'lex'
      
      TcGenDeriv is changed to generate code that uses the new libraries.
      The built-in instances of Read (List, Maybe, tuples, etc) use the new
      libraries.
      
      
      Other stuff
      ~~~~~~~~~~~
      1. Some fixes the the plumbing of external-core generation. Sigbjorn
      did most of the work earlier, but this commit completes the renaming and
      typechecking plumbing.
      
      2. Runtime error-generation functions, such as GHC.Err.recSelErr,
      GHC.Err.recUpdErr, etc, now take an Addr#, pointing to a UTF8-encoded
      C string, instead of a Haskell string.  This makes the *calls* to these
      functions easier to generate, and smaller too, which is a good thing.
      
      In particular, it means that MkId.mkRecordSelectorId doesn't need to
      be passed "unpackCStringId", which was GRUESOME; and that in turn means
      that tcTypeAndClassDecls doesn't need to be passed unf_env, which is
      a very worthwhile cleanup.   Win/win situation.
      
      3.  GHC now faithfully translates do-notation using ">>" for statements
      with no binding, just as the report says.  While I was there I tidied
      up HsDo to take a list of Ids instead of 3 (but now 4) separate Ids.
      Saves a bit of code here and there.  Also introduced Inst.newMethodFromName
      to package a common idiom.
      a7b95beb
  24. 05 Apr, 2002 1 commit
  25. 02 Apr, 2002 1 commit
    • simonmar's avatar
      [project @ 2002-04-02 13:56:32 by simonmar] · 94c5c5a2
      simonmar authored
      Allow the use of 'let' for implcit bindings.
      
      Support for 'with' is left in place for the time being, but on seeing
      a 'with' we emit a non-suppressible warning about 'with' being
      deprecated in favour of 'let'.
      94c5c5a2
  26. 01 Apr, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-04-01 08:23:30 by simonpj] · 9003a18c
      simonpj authored
      ------------------------------------
      	Change the treatment of the stupid
      	   context on data constructors
      	-----------------------------------
      
      Data types can have a context:
      
      	data (Eq a, Ord b) => T a b = T1 a b | T2 a
      
      and that makes the constructors have a context too
      (notice that T2's context is "thinned"):
      
      	T1 :: (Eq a, Ord b) => a -> b -> T a b
      	T2 :: (Eq a) => a -> T a b
      
      Furthermore, this context pops up when pattern matching
      (though GHC hasn't implemented this, but it is in H98, and
      I've fixed GHC so that it now does):
      
      	f (T2 x) = x
      gets inferred type
      	f :: Eq a => T a b -> a
      
      I say the context is "stupid" because the dictionaries passed
      are immediately discarded -- they do nothing and have no benefit.
      It's a flaw in the language.
      
      Up to now I have put this stupid context into the type of
      the "wrapper" constructors functions, T1 and T2, but that turned
      out to be jolly inconvenient for generics, and record update, and
      other functions that build values of type T (because they don't
      have suitable dictionaries available).
      
      So now I've taken the stupid context out.  I simply deal with
      it separately in the type checker on occurrences of a constructor,
      either in an expression or in a pattern.
      
      To this end
      
      * Lots of changes in DataCon, MkId
      
      * New function Inst.tcInstDataCon to instantiate a data constructor
      
      
      
      I also took the opportunity to
      
      * Rename
      	dataConId --> dataConWorkId
        for consistency.
      
      * Tidied up MkId.rebuildConArgs quite a bit, and renamed it
      	mkReboxingAlt
      
      * Add function DataCon.dataConExistentialTyVars, with the obvious meaning
      9003a18c
  27. 27 Mar, 2002 1 commit
  28. 25 Mar, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-03-25 15:08:38 by simonpj] · aaed1181
      simonpj authored
      -------------------------------
      	Fix bugs in rank-N polymorphism
      	-------------------------------
      
      Discussion with Mark showed up some bugs in the rank-N
      polymorphism stuff, especally concerning the treatment of
      'hole' type variables.
      
      See especially TcMType:
      	newHoleTyVar
      	readHoleResult
      	zapToType
      
      Also the treatment of conditionals and case branches
      is done right now, using zapToType
      aaed1181
  29. 08 Mar, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-03-08 15:50:53 by simonpj] · a170160c
      simonpj authored
      --------------------------------------
      	Lift the class-method type restriction
      	--------------------------------------
      
      Haskell 98 prohibits class method types to mention constraints on the
      class type variable, thus:
      
        class Seq s a where
          fromList :: [a] -> s a
          elem     :: Eq a => a -> s a -> Bool
      
      The type of 'elem' is illegal in Haskell 98, because it contains the
      constraint 'Eq a', which constrains only the class type variable (in
      this case 'a').
      
      This commit lifts the restriction.  The way we do that is to do a full
      context reduction (tcSimplifyCheck) step for each method separately in
      TcClassDcl.tcMethodBind, rather than doing a single context reduction
      for the whole group of method bindings.
      
      As a result, I had to reorganise the code a bit, and tidy up.
      a170160c
  30. 28 Feb, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-02-28 12:17:19 by simonpj] · 469c3333
      simonpj authored
      ---------------------------------
      	Fix a rather obscure bug in tcGen
      	---------------------------------
      
      This bug concerns deciding when a type variable "escapes",
      and hence we can't generalise it.  Our new subsumption-checking
      machinery for higher-ranked types requires a slightly
      more general approach than I had before.  The main excitement
      is in TcUnify.checkSigTyVars and its friends.
      
      As usual, I moved functions around and cleaned things up a bit;
      hence the multi-module commit.
      469c3333
  31. 13 Feb, 2002 1 commit
    • simonpj's avatar
      [project @ 2002-02-13 15:14:06 by simonpj] · e7030995
      simonpj authored
      --------------------------------------------
      	Fix a bugs in type inference for rank-N types
      	--------------------------------------------
      
      We discovered this bug when looking at type rules!
      
      1. When type checking (e :: sigma-ty), we must specialise sigma-ty,
         else we lose the invariant that tcMonoType has.
      
      2. In tcExpr_id, we should pass in a Hole tyvar not an ordinary tyvar.
      
      As usual, I moved some functions around in consequence.
      e7030995
  32. 11 Feb, 2002 1 commit
    • chak's avatar
      [project @ 2002-02-11 08:20:38 by chak] · 10fcd78c
      chak authored
      *******************************
      		       * Merging from ghc-ndp-branch *
      		       *******************************
      
      This commit merges the current state of the "parallel array extension" and
      includes the following:
      
      * (Almost) completed Milestone 1:
        - The option `-fparr' activates the H98 extension for parallel arrays.
        - These changes have a high likelihood of conflicting (in the CVS sense)
          with other changes to GHC and are the reason for merging now.
        - ToDo: There are still some (less often used) functions not implemented in
      	  `PrelPArr' and a mechanism is needed to automatically import
      	  `PrelPArr' iff `-fparr' is given.  Documentation that should go into
      	  the Commentary is currently in `ghc/compiler/ndpFlatten/TODO'.
      
      * Partial Milestone 2:
        - The option `-fflatten' activates the flattening transformation and `-ndp'
          selects the "ndp" way (where all libraries have to be compiled with
          flattening).  The way option `-ndp' automagically turns on `-fparr' and
          `-fflatten'.
        - Almost all changes are in the new directory `ndpFlatten' and shouldn't
          affect the rest of the compiler.  The only exception are the options and
          the points in `HscMain' where the flattening phase is called when
          `-fflatten' is given.
        - This isn't usable yet, but already implements function lifting,
          vectorisation, and a new analysis that determines which parts of a module
          have to undergo the flattening transformation.  Missing are data structure
          and function specialisation, the unboxed array library (including fusion
          rules), and lots of testing.
      
      I have just run the regression tests on the thing without any problems.  So,
      it seems, as if we haven't broken anything crucial.
      10fcd78c
  33. 30 Nov, 2001 1 commit
  34. 26 Nov, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-11-26 09:20:25 by simonpj] · 5e3f005d
      simonpj authored
      ----------------------
      	Implement Rank-N types
      	----------------------
      
      This commit implements the full glory of Rank-N types, using
      the Odersky/Laufer approach described in their paper
      	"Putting type annotations to work"
      
      In fact, I've had to adapt their approach to deal with the
      full glory of Haskell (including pattern matching, and the
      scoped-type-variable extension).  However, the result is:
      
      * There is no restriction to rank-2 types.  You can nest forall's
        as deep as you like in a type.  For example, you can write a type
        like
      	p :: ((forall a. Eq a => a->a) -> Int) -> Int
        This is a rank-3 type, illegal in GHC 5.02
      
      * When matching types, GHC uses the cunning Odersky/Laufer coercion
        rules.  For example, suppose we have
      	q :: (forall c. Ord c => c->c) -> Int
        Then, is this well typed?
      	x :: Int
      	x = p q
        Yes, it is, but GHC has to generate the right coercion.  Here's
        what it looks like with all the big lambdas and dictionaries put in:
      
      	x = p (\ f :: (forall a. Eq a => a->a) ->
      		 q (/\c \d::Ord c -> f c (eqFromOrd d)))
      
        where eqFromOrd selects the Eq superclass dictionary from the Ord
        dicationary:		eqFromOrd :: Ord a -> Eq a
      
      
      * You can use polymorphic types in pattern type signatures.  For
        example:
      
      	f (g :: forall a. a->a) = (g 'c', g True)
      
        (Previously, pattern type signatures had to be monotypes.)
      
      * The basic rule for using rank-N types is that you must specify
        a type signature for every binder that you want to have a type
        scheme (as opposed to a plain monotype) as its type.
      
        However, you don't need to give the type signature on the
        binder (as I did above in the defn for f).  You can give it
        in a separate type signature, thus:
      
      	f :: (forall a. a->a) -> (Char,Bool)
      	f g = (g 'c', g True)
      
        GHC will push the external type signature inwards, and use
        that information to decorate the binders as it comes across them.
        I don't have a *precise* specification of this process, but I
        think it is obvious enough in practice.
      
      * In a type synonym you can use rank-N types too.  For example,
        you can write
      
      	type IdFun = forall a. a->a
      
      	f :: IdFun -> (Char,Bool)
      	f g = (g 'c', g True)
      
        As always, type synonyms must always occur saturated; GHC
        expands them before it does anything else.  (Still, GHC goes
        to some trouble to keep them unexpanded in error message.)
      
      
      The main plan is as before.  The main typechecker for expressions,
      tcExpr, takes an "expected type" as its argument.  This greatly
      improves error messages.  The new feature is that when this
      "expected type" (going down) meets an "actual type" (coming up)
      we use the new subsumption function
      	TcUnify.tcSub
      which checks that the actual type can be coerced into the
      expected type (and produces a coercion function to demonstrate).
      
      The main new chunk of code is TcUnify.tcSub.  The unifier itself
      is unchanged, but it has moved from TcMType into TcUnify.  Also
      checkSigTyVars has moved from TcMonoType into TcUnify.
      Result: the new module, TcUnify, contains all stuff relevant
      to subsumption and unification.
      
      Unfortunately, there is now an inevitable loop between TcUnify
      and TcSimplify, but that's just too bad (a simple TcUnify.hi-boot
      file).
      
      
      All of this doesn't come entirely for free.  Here's the typechecker
      line count (INCLUDING comments)
      	Before	16,551
      	After	17,116
      5e3f005d
  35. 31 Oct, 2001 1 commit
    • simonpj's avatar
      [project @ 2001-10-31 15:22:53 by simonpj] · 61bfd5dd
      simonpj authored
      ------------------------------------------
      	Improved handling of scoped type variables
      	------------------------------------------
      
      The main effect of this commit is to allow scoped type variables
      in pattern bindings, thus
      
      	(x::a, y::b) = e
      
      This was illegal, but now it's ok.  a and b have the same scope
      as x and y.
      
      
      On the way I beefed up the info inside a type variable
      (TcType.TyVarDetails; c.f. IdInfo.GlobalIdDetails) which
      helps to improve error messages. Hence the wide ranging changes.
      Pity about the extra loop from Var to TcType, but can't be helped.
      61bfd5dd