[project @ 2000-09-22 15:56:12 by simonpj]
authorsimonpj <unknown>
Fri, 22 Sep 2000 15:56:16 +0000 (15:56 +0000)
committersimonpj <unknown>
Fri, 22 Sep 2000 15:56:16 +0000 (15:56 +0000)
commit1bba522f5ec82c43abd2ba4e84127b9c915dd020
tree1a912e2e7f74da8abcca375d2559cb985af17544
parenta8e1967fbb90eae923042827cef98a98d66d18e7
[project @ 2000-09-22 15:56:12 by simonpj]
--------------------------------------------------
Tidying up HsLit, and making it possible to define
your own numeric library

Simon PJ 22 Sept 00
--------------------------------------------------

** NOTE: I did these changes on the aeroplane.  They should compile,
 and the Prelude still compiles OK, but it's entirely
 possible that I've broken something

The original reason for this many-file but rather shallow
commit is that it's impossible in Haskell to write your own
numeric library.  Why?  Because when you say '1' you get
(Prelude.fromInteger 1), regardless of what you hide from the
Prelude, or import from other libraries you have written.  So the
idea is to extend the -fno-implicit-prelude flag so that
in addition to no importing the Prelude, you can rebind
fromInteger -- Applied to literal constants
fromRational -- Ditto
negate -- Invoked by the syntax (-x)
the (-) used when desugaring n+k patterns

After toying with other designs, I eventually settled on a simple,
crude one: rather than adding a new flag, I just extended the
semantics of -fno-implicit-prelude so that uses of fromInteger,
fromRational and negate are all bound to "whatever is in scope"
rather than "the fixed Prelude functions".  So if you say

{-# OPTIONS -fno-implicit-prelude #-}
module M where
  import MyPrelude( fromInteger )

x = 3

the literal 3 will use whatever (unqualified) "fromInteger" is in scope,
in this case the one gotten from MyPrelude.

On the way, though, I studied how HsLit worked, and did a substantial tidy
up, deleting quite a lot of code along the way.  In particular.

* HsBasic.lhs is renamed HsLit.lhs.  It defines the HsLit type.

* There are now two HsLit types, both defined in HsLit.
HsLit for non-overloaded literals (like 'x')
HsOverLit for overloaded literals (like 1 and 2.3)

* HsOverLit completely replaces Inst.OverloadedLit, which disappears.
  An HsExpr can now be an HsOverLit as well as an HsLit.

* HsOverLit carries the Name of the fromInteger/fromRational operation,
  so that the renamer can help with looking up the unqualified name
  when -fno-implicit-prelude is on.  Ditto the HsExpr for negation.
  It's all very tidy now.

* RdrHsSyn contains the stuff that handles -fno-implicit-prelude
  (see esp RdrHsSyn.prelQual).  RdrHsSyn also contains all the "smart constructors"
  used by the parser when building HsSyn.  See for example RdrHsSyn.mkNegApp
  (previously the renamer (!) did the business of turning (- 3#) into -3#).

* I tidied up the handling of "special ids" in the parser.  There's much
  less duplication now.

* Move Sven's Horner stuff to the desugarer, where it belongs.
  There's now a nice function DsUtils.mkIntegerLit which brings together
  related code from no fewer than three separate places into one single
  place.  Nice!

* A nice tidy-up in MatchLit.partitionEqnsByLit became possible.

* Desugaring of HsLits is now much tidier (DsExpr.dsLit)

* Some stuff to do with RdrNames is moved from ParseUtil.lhs to RdrHsSyn.lhs,
  which is where it really belongs.

* I also removed
many unnecessary imports from modules
quite a bit of dead code
  in divers places
52 files changed:
ghc/compiler/basicTypes/RdrName.lhs
ghc/compiler/basicTypes/Unique.lhs
ghc/compiler/basicTypes/Var.lhs
ghc/compiler/deSugar/Check.lhs
ghc/compiler/deSugar/DsBinds.lhs
ghc/compiler/deSugar/DsExpr.lhs
ghc/compiler/deSugar/DsGRHSs.lhs
ghc/compiler/deSugar/DsUtils.lhs
ghc/compiler/deSugar/Match.lhs
ghc/compiler/deSugar/MatchLit.lhs
ghc/compiler/hsSyn/HsDecls.lhs
ghc/compiler/hsSyn/HsExpr.lhs
ghc/compiler/hsSyn/HsPat.lhs
ghc/compiler/hsSyn/HsSyn.lhs
ghc/compiler/main/MkIface.lhs
ghc/compiler/parser/ParseUtil.lhs
ghc/compiler/parser/Parser.y
ghc/compiler/parser/RdrHsSyn.lhs
ghc/compiler/prelude/PrelInfo.lhs
ghc/compiler/prelude/PrelNames.lhs
ghc/compiler/rename/ParseIface.y
ghc/compiler/rename/Rename.lhs
ghc/compiler/rename/RnBinds.lhs
ghc/compiler/rename/RnEnv.lhs
ghc/compiler/rename/RnExpr.lhs
ghc/compiler/rename/RnHsSyn.lhs
ghc/compiler/rename/RnIfaces.lhs
ghc/compiler/rename/RnMonad.lhs
ghc/compiler/rename/RnNames.lhs
ghc/compiler/rename/RnSource.lhs
ghc/compiler/stgSyn/StgInterp.lhs
ghc/compiler/typecheck/Inst.lhs
ghc/compiler/typecheck/TcBinds.lhs
ghc/compiler/typecheck/TcClassDcl.lhs
ghc/compiler/typecheck/TcDeriv.lhs
ghc/compiler/typecheck/TcExpr.lhs
ghc/compiler/typecheck/TcForeign.lhs
ghc/compiler/typecheck/TcGenDeriv.lhs
ghc/compiler/typecheck/TcIfaceSig.lhs
ghc/compiler/typecheck/TcImprove.lhs
ghc/compiler/typecheck/TcInstDcls.lhs
ghc/compiler/typecheck/TcInstUtil.lhs
ghc/compiler/typecheck/TcMatches.lhs
ghc/compiler/typecheck/TcModule.lhs
ghc/compiler/typecheck/TcMonad.lhs
ghc/compiler/typecheck/TcMonoType.lhs
ghc/compiler/typecheck/TcPat.lhs
ghc/compiler/typecheck/TcRules.lhs
ghc/compiler/typecheck/TcSimplify.lhs
ghc/compiler/typecheck/TcTyClsDecls.lhs
ghc/compiler/typecheck/TcTyDecls.lhs
ghc/compiler/types/Type.lhs