GHC:44c2d7662bd6074206c422533d3963cdb44e7199 commitshttps://gitlab.haskell.org/ghc/ghc/-/commits/44c2d7662bd6074206c422533d3963cdb44e71992002-06-17T16:21:42+00:00https://gitlab.haskell.org/ghc/ghc/-/commit/44c2d7662bd6074206c422533d3963cdb44e7199[project @ 2002-06-17 16:21:42 by simonpj]2002-06-17T16:21:42+00:00simonpjunknownIgnore fewer type errors in tcSimplifyTop; fixes tc106https://gitlab.haskell.org/ghc/ghc/-/commit/61193fe4e9c4c47c44b37524db091c1fa71f3a45[project @ 2002-05-23 15:51:26 by simonpj]2002-05-23T15:51:26+00:00simonpjunknownDon't report ambiguity errors
if other type errors have happened
This saves a gratuitous error cascade when the type checker
recovers from one error by giving f type (forall a.a), and
then find an ambiguity problem as a direct result.https://gitlab.haskell.org/ghc/ghc/-/commit/371b6a0c9895676666c14d53a98d48e83b53ea51[project @ 2002-04-10 13:52:49 by simonpj]2002-04-10T13:52:49+00:00simonpjunknownMake the earlier context-simplification loop-detection fix work properlyhttps://gitlab.haskell.org/ghc/ghc/-/commit/13878c136b4e6b676dbc859f378809676f4d679c[project @ 2002-04-02 13:21:36 by simonpj]2002-04-02T13:21:37+00:00simonpjunknown-----------------------------------------------------
Fix two nasty, subtle loops in context simplification
-----------------------------------------------------
The context simplifier in TcSimplify was building a recursive
dictionary, which meant the program looped when run. The reason
was pretty devious; in fact there are two independent causes.
Cause 1
~~~~~~~
Consider
class Eq b => Foo a b
instance Eq a => Foo [a] a
If we are reducing
d:Foo [t] t
we'll first deduce that it holds (via the instance decl), thus:
d:Foo [t] t = $fFooList deq
deq:Eq t = ...some rhs depending on t...
Now we add d's superclasses. We must not then overwrite the Eq t
constraint with a superclass selection!!
The only decent way to solve this is to track what dependencies
a binding has; that is what the is_loop parameter to TcSimplify.addSCs
now does.
Cause 2
~~~~~~~
This shows up when simplifying the superclass context of an
instance declaration. Consider
class S a
class S a => C a where { opc :: a -> a }
class S b => D b where { opd :: b -> b }
instance C Int where
opc = opd
instance D Int where
opd = opc
From (instance C Int) we get the constraint set {ds1:S Int, dd:D Int}
Simplifying, we may well get:
$dfCInt = :C ds1 (opd dd)
dd = $dfDInt
ds1 = $p1 dd
Notice that we spot that we can extract ds1 from dd.
Alas! Alack! We can do the same for (instance D Int):
$dfDInt = :D ds2 (opc dc)
dc = $dfCInt
ds2 = $p1 dc
And now we've defined the superclass in terms of itself.
Solution: treat the superclass context separately, and simplify it
all the way down to nothing on its own. Don't toss any 'free' parts
out to be simplified together with other bits of context.
This is done in TcInstDcls.tcSuperClasses, which is well commented.
All this from a bug report from Peter White!https://gitlab.haskell.org/ghc/ghc/-/commit/0b98d0b4072d643f3aacfee5e38519c74af0dd5d[project @ 2002-03-27 12:07:42 by simonpj]2002-03-27T12:07:45+00:00simonpjunknownComments and tracing onlyhttps://gitlab.haskell.org/ghc/ghc/-/commit/b73019e2bf2b0c58e1d669f8fd44188ad16e950e[project @ 2002-03-18 15:21:59 by simonpj]2002-03-18T15:21:59+00:00simonpjunknownFix grevious bug in linear implicit parameter splitting for free Instshttps://gitlab.haskell.org/ghc/ghc/-/commit/a170160cc21678c30ca90696d4ae0fc1155f25bf[project @ 2002-03-08 15:50:53 by simonpj]2002-03-08T15:50:57+00:00simonpjunknown--------------------------------------
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.https://gitlab.haskell.org/ghc/ghc/-/commit/b383edf27f587a9d7aaa241638b7bef6c1a54149[project @ 2002-02-15 09:32:47 by simonpj]2002-02-15T09:32:47+00:00simonpjunknownComments onlyhttps://gitlab.haskell.org/ghc/ghc/-/commit/e70309951a888dfa8629b2e07dbc30795550f868[project @ 2002-02-13 15:14:06 by simonpj]2002-02-13T15:14:07+00:00simonpjunknown--------------------------------------------
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.https://gitlab.haskell.org/ghc/ghc/-/commit/10fcd78ccde892feccda3f5eacd221c1de75feea[project @ 2002-02-11 08:20:38 by chak]2002-02-11T08:20:50+00:00chakunknown*******************************
* 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.https://gitlab.haskell.org/ghc/ghc/-/commit/35c63bfcf979854cbe034a134dbcb7505313bbef[project @ 2002-02-07 12:50:00 by simonpj]2002-02-07T12:50:47+00:00simonpjunknownBetter pretty printinghttps://gitlab.haskell.org/ghc/ghc/-/commit/f50b860a322b27a2c45e486bfd3da30393cdb03c[project @ 2002-02-05 14:46:26 by simonpj]2002-02-05T14:46:27+00:00simonpjunknownImports onlyhttps://gitlab.haskell.org/ghc/ghc/-/commit/b08335c943c8a31e298e02ff776c1844e0536257[project @ 2002-02-01 11:38:32 by simonpj]2002-02-01T11:38:33+00:00simonpjunknownMore wibbles on deriving with -fallow-undecidable-instanceshttps://gitlab.haskell.org/ghc/ghc/-/commit/b27560c4649d7025456fb9936d5a5cdd1e5dc383[project @ 2002-01-31 17:48:26 by simonpj]2002-01-31T17:48:27+00:00simonpjunknownWibbles to yesterdays changeshttps://gitlab.haskell.org/ghc/ghc/-/commit/ae969b4759e1914cb44bf126fc56e2e059d050dc[project @ 2001-12-28 17:25:31 by simonpj]2001-12-28T17:25:32+00:00simonpjunknown---------------------
Dealing with deriving
---------------------
I spent a ridiculously long time peering at a bug report whereby
a 'deriving' clause sent GHC 5.02.1 into a loop. It was all to
do with allowing instances like
instance Foo a b => Baz (T a)
(Notice the 'b' on the left which does not appear on the right.)
I realised that it's hard for the deriving machinery to find a
fixpoint when these sort of instance decls are around. So I
now constrain *derived* instance decls not to have this form;
all the tyvars on the left must appear on the right.
On the way I commoned up the previously-separate tcSimplify
machinery for 'deriving' and 'default' decls with that for
everything else. As a result, quite a few files are touched.
I hope I havn't broken anything.https://gitlab.haskell.org/ghc/ghc/-/commit/91c750cbd18e3d610b0db498ded38d5b3c5adfac[project @ 2001-12-20 11:19:05 by simonpj]2001-12-20T11:19:12+00:00simonpjunknown---------------------------------------------
More type system extensions (for John Hughes)
---------------------------------------------
1. Added a brand-new extension that lets you derive ARBITRARY CLASSES
for newtypes. Thus
newtype Age = Age Int deriving( Eq, Ord, Shape, Ix )
The idea is that the dictionary for the user-defined class Shape Age
is *identical* to that for Shape Int, so there is really no deriving
work to do. This saves you writing the very tiresome instance decl:
instance Shape Age where
shape_op1 (Age x) = shape_op1 x
shape_op2 (Age x1) (Age x2) = shape_op2 x1 x2
...etc...
It's more efficient, too, becuase the Shape Age dictionary really
will be identical to the Shape Int dictionary.
There's an exception for Read and Show, because the derived instance
*isn't* the same.
There is a complication where higher order stuff is involved. Here is
the example John gave:
class StateMonad s m | m -> s where ...
newtype Parser tok m a = Parser (State [tok] (Failure m) a)
deriving( Monad, StateMonad )
Then we want the derived instance decls to be
instance Monad (State [tok] (Failure m)) => Monad (Parser tok m)
instance StateMonad [tok] (State [tok] (Failure m))
=> StateMonad [tok] (Parser tok m)
John is writing up manual entry for all of this, but this commit
implements it. I think.
2. Added -fallow-incoherent-instances, and documented it. The idea
is that sometimes GHC is over-protective about not committing to a
particular instance, and the programmer may want to say "commit anyway".
Here's the example:
class Sat a where
dict :: a
data EqD a = EqD {eq :: a->a->Bool}
instance Sat (EqD a) => Eq a where
(==) = eq dict
instance Sat (EqD Integer) where
dict = EqD{eq=(==)}
instance Eq a => Sat (EqD a) where
dict = EqD{eq=(==)}
class Collection c cxt | c -> cxt where
empty :: Sat (cxt a) => c a
single :: Sat (cxt a) => a -> c a
union :: Sat (cxt a) => c a -> c a -> c a
member :: Sat (cxt a) => a -> c a -> Bool
instance Collection [] EqD where
empty = []
single x = [x]
union = (++)
member = elem
It's an updated attempt to model "Restricted Data Types", if you
remember my Haskell workshop paper. In the end, though, GHC rejects
the program (even with fallow-overlapping-instances and
fallow-undecideable-instances), because there's more than one way to
construct the Eq instance needed by elem.
Yet all the ways are equivalent! So GHC is being a bit over-protective
of me, really: I know what I'm doing and I would LIKE it to pick an
arbitrary one. Maybe a flag fallow-incoherent-instances would be a
useful thing to add?https://gitlab.haskell.org/ghc/ghc/-/commit/32a895831dbc202fab780fdd8bee65be81e2d232[project @ 2001-11-29 13:47:09 by simonpj]2001-11-29T13:47:12+00:00simonpjunknown------------------------------
Add linear implicit parameters
------------------------------
Linear implicit parameters are an idea developed by Koen Claessen,
Mark Shields, and Simon PJ, last week. They address the long-standing
problem that monads seem over-kill for certain sorts of problem, notably:
* distributing a supply of unique names
* distributing a suppply of random numbers
* distributing an oracle (as in QuickCheck)
Linear implicit parameters are just like ordinary implicit parameters,
except that they are "linear" -- that is, they cannot be copied, and
must be explicitly "split" instead. Linear implicit parameters are
written '%x' instead of '?x'. (The '/' in the '%' suggests the
split!)
For example:
data NameSupply = ...
splitNS :: NameSupply -> (NameSupply, NameSupply)
newName :: NameSupply -> Name
instance PrelSplit.Splittable NameSupply where
split = splitNS
f :: (%ns :: NameSupply) => Env -> Expr -> Expr
f env (Lam x e) = Lam x' (f env e)
where
x' = newName %ns
env' = extend env x x'
...more equations for f...
Notice that the implicit parameter %ns is consumed
once by the call to newName
once by the recursive call to f
So the translation done by the type checker makes
the parameter explicit:
f :: NameSupply -> Env -> Expr -> Expr
f ns env (Lam x e) = Lam x' (f ns1 env e)
where
(ns1,ns2) = splitNS ns
x' = newName ns2
env = extend env x x'
Notice the call to 'split' introduced by the type checker.
How did it know to use 'splitNS'? Because what it really did
was to introduce a call to the overloaded function 'split',
ndefined by
class Splittable a where
split :: a -> (a,a)
The instance for Splittable NameSupply tells GHC how to implement
split for name supplies. But we can simply write
g x = (x, %ns, %ns)
and GHC will infer
g :: (Splittable a, %ns :: a) => b -> (b,a,a)
The Splittable class is built into GHC. It's defined in PrelSplit,
and exported by GlaExts.
Other points:
* '?x' and '%x' are entirely distinct implicit parameters: you
can use them together and they won't intefere with each other.
* You can bind linear implicit parameters in 'with' clauses.
* You cannot have implicit parameters (whether linear or not)
in the context of a class or instance declaration.
Warnings
~~~~~~~~
The monomorphism restriction is even more important than usual.
Consider the example above:
f :: (%ns :: NameSupply) => Env -> Expr -> Expr
f env (Lam x e) = Lam x' (f env e)
where
x' = newName %ns
env' = extend env x x'
If we replaced the two occurrences of x' by (newName %ns), which is
usually a harmless thing to do, we get:
f :: (%ns :: NameSupply) => Env -> Expr -> Expr
f env (Lam x e) = Lam (newName %ns) (f env e)
where
env' = extend env x (newName %ns)
But now the name supply is consumed in *three* places
(the two calls to newName,and the recursive call to f), so
the result is utterly different. Urk! We don't even have
the beta rule.
Well, this is an experimental change. With implicit
parameters we have already lost beta reduction anyway, and
(as John Launchbury puts it) we can't sensibly reason about
Haskell programs without knowing their typing.
Of course, none of this is throughly tested, either.https://gitlab.haskell.org/ghc/ghc/-/commit/5e3f005d3012472e422d4ffd7dca5c21a80fca80[project @ 2001-11-26 09:20:25 by simonpj]2001-11-26T09:20:28+00:00simonpjunknown----------------------
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,116https://gitlab.haskell.org/ghc/ghc/-/commit/61bfd5dd3b9d70404d6f93c030a9bb1c402b9d31[project @ 2001-10-31 15:22:53 by simonpj]2001-10-31T15:22:55+00:00simonpjunknown------------------------------------------
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.https://gitlab.haskell.org/ghc/ghc/-/commit/d5f94cc150c18a060e96795010b30bbcdf7bbc17[project @ 2001-10-25 14:30:43 by simonpj]2001-10-25T14:30:43+00:00simonpjunknown-------------------------------------------------------
Correct an error in the handling of implicit parameters
-------------------------------------------------------
MERGE WITH STABLE BRANCH UNLESS HARD TO DO
Mark Shields discovered a bug in the way that implicit parameters
are dealt with by the type checker. It's all a bit subtle, and
is extensively documented in TcSimplify.lhs.
This commit makes the code both simpler and more correct. It subtly
changes the way in which type signatures are treated, but not in a way
anyone would notice: see notes with "Question 2: type signatures"
in TcSimplify.lhs.https://gitlab.haskell.org/ghc/ghc/-/commit/2007c7e67ddea6e16f4c8e013a453b073232459a[project @ 2001-10-25 09:58:39 by simonpj]2001-10-25T09:58:39+00:00simonpjunknownCosmeticahttps://gitlab.haskell.org/ghc/ghc/-/commit/f342fa9eb5b376fa5fcaa53c9ec5b0030301e36f[project @ 2001-10-17 15:38:43 by simonpj]2001-10-17T15:38:43+00:00simonpjunknownAdd commentshttps://gitlab.haskell.org/ghc/ghc/-/commit/ad6bc60d7330ec56c08fd81e1d992b5ed2db8a57[project @ 2001-08-28 10:03:23 by simonpj]2001-08-28T10:03:24+00:00simonpjunknownAdd pprEquationhttps://gitlab.haskell.org/ghc/ghc/-/commit/27f289f3190d7eedf758d3f2c08697a042186691[project @ 2001-08-20 07:54:33 by simonpj]2001-08-20T07:54:33+00:00simonpjunknownImprove error messages from the typechecker,
after a suggestion from Alastair Reid.https://gitlab.haskell.org/ghc/ghc/-/commit/7fde87b3698ae84e1b6006a1c3ed0b2fd974b686[project @ 2001-07-25 15:55:30 by simonpj]2001-07-25T15:55:30+00:00simonpjunknown-----------------------------------------
Fix a bug in the monomorphism restriction
------------------------------------------
Thanks for Koen for reporting this bug.
In tcSimplifyRestricted, I wrongly called tcSimpifyToDicts,
whereas actually we have to simplfy further than simply to
a dictionary.
The test for this is in typecheck/should_compile/tc132.hshttps://gitlab.haskell.org/ghc/ghc/-/commit/b20ad44787ce6f778de86aebe9504cbb11779d01[project @ 2001-07-23 10:24:57 by simonpj]2001-07-23T10:24:58+00:00simonpjunknownYet another newtype-squashing bug; this time TcType.unifyTyXhttps://gitlab.haskell.org/ghc/ghc/-/commit/5f6ec2cada6832bc0a20e8dded8252f9e9c750e9[project @ 2001-07-17 09:55:09 by qrczak]2001-07-17T09:55:09+00:00qrczakunknownTypos in a comment. Whitespace at eols.https://gitlab.haskell.org/ghc/ghc/-/commit/ab46fd8e68f10b6162e77cfc0b216510d9b1d933[project @ 2001-07-12 16:21:22 by simonpj]2001-07-12T16:21:24+00:00simonpjunknown--------------------------------------------
Fix another bug in the squash-newtypes story.
--------------------------------------------
[This one was spotted by Marcin, and is now enshrined in test tc130.]
The desugarer straddles the boundary between the type checker and
Core, so it sometimes needs to look through newtypes/implicit parameters
and sometimes not. This is really a bit painful, but I can't think of
a better way to do it.
The only simple way to fix things was to pass a bit more type
information in the HsExpr type, from the type checker to the desugarer.
That led to the non-local changes you can see.
On the way I fixed one other thing. In various HsSyn constructors
there is a Type that is bogus (bottom) before the type checker, and
filled in with a real type by the type checker. In one place it was
a (Maybe Type) which was Nothing before, and (Just ty) afterwards.
I've defined a type synonym HsTypes.PostTcType for this, and a named
bottom value HsTypes.placeHolderType to use when you want the bottom
value.https://gitlab.haskell.org/ghc/ghc/-/commit/a12bed5371650117aab631ac032fb1b525570c00[project @ 2001-06-25 08:01:16 by simonpj]2001-06-25T08:01:16+00:00simonpjunknown----------------------------------
Fix a predicate-simplification bug
----------------------------------
Fixes a bug pointed out by Marcin
data R = R {f :: Int}
foo:: (?x :: Int) => R -> R
foo r = r {f = ?x}
Test.hs:4:
Could not deduce `?x :: Int' from the context ()
arising from use of implicit parameter `?x' at Test.hs:4
In the record update: r {f = ?x}
In the definition of `foo': r {f = ?x}
The predicate simplifier was declining to 'inherit' an
implicit parameter. This is right for a let-binding, but
wrong for an expression binding. For example, a simple
expression type signature:
(?x + 1) :: Int
This was rejected because the ?x constraint could not be
floated out -- but that's wrong for expressions.https://gitlab.haskell.org/ghc/ghc/-/commit/bbc670f4ac4428a3a13ab34c2843381a82698ff4[project @ 2001-05-03 12:33:50 by simonpj]2001-05-03T12:33:50+00:00simonpjunknown**** MERGE WITH 5.00 BRANCH ********
--------------------------------
Monomorphism restriction for implicit parameters
--------------------------------
This commit tidies up the way in which monomorphic bindings
are dealt with, incidentally fixing a bug to do with implicit
parameters.
The tradeoffs concerning monomorphism and implicit paramters are
now documented in TcSimplify.lhs, and all the strategic choices
are made there (rather than in TcBinds where they were before).
I've continued with choice (B) -- which Jeff first implemented --
because that's what Hugs does, lacking any other consensus.https://gitlab.haskell.org/ghc/ghc/-/commit/b473b6c241cf54b5edc1e21553250739476c0cf9[project @ 2001-05-03 09:32:48 by simonpj]2001-05-03T09:32:49+00:00simonpjunknown------------------------------------------------
Dramatically improve the error messages arising
from failed unifications triggered by 'improvement'
------------------------------------------------
A bit more plumbing in FunDeps, and consequential wibbles elsewhere
Changes this:
Couldn't match `Int' against `[(String, Int)]'
Expected type: Int
Inferred type: [(String, Int)]
to this:
Foo.hs:8:
Couldn't match `Int' against `[(String, Int)]'
Expected type: Int
Inferred type: [(String, Int)]
When using functional dependencies to combine
?env :: Int, arising from a type signature at Foo.hs:7
?env :: [(String, Int)],
arising from use of implicit parameter `?env' at Foo.hs:8
When generalising the types for identhttps://gitlab.haskell.org/ghc/ghc/-/commit/cd7dc9b1d4277ead419f45264fead9ef02b65bcb[project @ 2001-05-03 08:13:25 by simonpj]2001-05-03T08:13:25+00:00simonpjunknown**** MERGE WITH 5.00 BRANCH ********
--------------------------------
Fix a bad implicit parameter bug
--------------------------------
TcSimplify.tcSimplifyIPs was just completely wrong; it wasn't
doing improvement properly nor binding values properly. Sigh.
To make this work nicely I added
Inst.instName :: Inst -> Namehttps://gitlab.haskell.org/ghc/ghc/-/commit/73b92b542bb06d33cffd0f548603dd0a4872294a[project @ 2001-04-30 10:49:38 by simonpj]2001-04-30T10:49:38+00:00simonpjunknownAdd commentshttps://gitlab.haskell.org/ghc/ghc/-/commit/ebf2c80221ccf11aeb7a0a2be27bfc72529855a5[project @ 2001-04-12 21:29:43 by lewie]2001-04-12T21:29:43+00:00lewieunknownDon't use the same simplify code for both restricted and unrestricted
bindings. In particular, a restricted binding shouldn't try to capture
implicit params.https://gitlab.haskell.org/ghc/ghc/-/commit/b58e1155b0ec79ec6983c3e9a42880d511b7bc10[project @ 2001-04-05 11:28:53 by simonpj]2001-04-05T11:28:53+00:00simonpjunknownImprove error reportinghttps://gitlab.haskell.org/ghc/ghc/-/commit/788faebb40b51d37e73ed94dfc99460d39a1a811[project @ 2001-03-13 14:58:25 by simonpj]2001-03-13T14:58:28+00:00simonpjunknown----------------
Nuke ClassContext
----------------
This commit tidies up a long-standing inconsistency in GHC.
The context of a class or instance decl used to be restricted
to predicates of the form
C t1 .. tn
with
type ClassContext = [(Class,[Type])]
but everywhere else in the compiler we used
type ThetaType = [PredType]
where PredType can be any sort of constraint (= predicate).
The inconsistency actually led to a crash, when compiling
class (?x::Int) => C a where {}
I've tidied all this up by nuking ClassContext altogether, and using
PredType throughout. Lots of modified files, but all in
more-or-less trivial ways.
I've also added a check that the context of a class or instance
decl doesn't include a non-inheritable predicate like (?x::Int).
Other things
* rename constructor 'Class' from type TypeRep.Pred to 'ClassP'
(makes it easier to grep for)
* rename constructor HsPClass => HsClassP
HsPIParam => HsIParamhttps://gitlab.haskell.org/ghc/ghc/-/commit/56d75e0bcd599a167deb7ef10dfb8b18b6529940[project @ 2001-02-28 17:17:55 by simonpj]2001-02-28T17:17:55+00:00simonpjunknownImprove rule matching
When doing constraint simplification on the LHS of a rule,
we *don't* want to do superclass commoning up. Consider
fromIntegral :: (Integral a, Num b) => a -> b
{-# RULES "foo" fromIntegral = id :: Int -> Int #-}
Here, a=b=Int, and Num Int is a superclass of Integral Int. But we *dont*
want to get
forall dIntegralInt.
fromIntegral Int Int dIntegralInt (scsel dIntegralInt) = id Int
because the scsel (super class selection) will mess up matching.
Instead we want
forall dIntegralInt, dNumInt.
fromIntegral Int Int dIntegralInt dNumInt = id Int
TcSimplify.tcSimplifyToDicts is the relevant function, but I had
to generalise the main simplification loop a little (adding the
type WantSCs).https://gitlab.haskell.org/ghc/ghc/-/commit/1c62b517711ac232a8024d91fd4b317a6804d28e[project @ 2001-02-26 15:06:57 by simonmar]2001-02-26T15:07:02+00:00simonmarunknownImplement do-style bindings on the GHCi command line.
The syntax for a command-line is exactly that of a do statement, with
the following meanings:
- `pat <- expr'
performs expr, and binds each of the variables in pat.
- `let pat = expr; ...'
binds each of the variables in pat, doesn't do any evaluation
- `expr'
behaves as `it <- expr' if expr is IO-typed, or `let it = expr'
followed by `print it' otherwise.https://gitlab.haskell.org/ghc/ghc/-/commit/22ffc06ab94bba69b7e45d90ccd5885d9fcc456e[project @ 2001-02-20 09:42:50 by simonpj]2001-02-20T09:42:50+00:00simonpjunknownTypechecking [TcModule, TcBinds, TcHsSyn, TcInstDcls, TcSimplify]
~~~~~~~~~~~~
* Fix a bug in TcSimplify that broke functional dependencies.
Interleaving unification and context reduction is trickier
than I thought. Comments in the code amplify.
* Fix a functional-dependency bug, that meant that this pgm:
class C a b | a -> b where f :: a -> b
g :: (C a b, Eq b) => a -> Bool
g x = f x == f x
gave an ambiguity error report. I'm afraid I've forgotten
what the problem was.
* Correct the implementation of the monomorphism restriction,
in TcBinds.generalise. This fixes Marcin's bug report:
test1 :: Eq a => a -> b -> b
test1 x y = y
test2 = test1 (3::Int)
Previously we were erroneously inferring test2 :: () -> ()
* Make the "unf_env" that is looped round in TcModule go round
in a big loop, not just round tcImports. This matters when
we have mutually recursive modules, so that the Ids bound in
the source code may appear in the imports. Sigh. But no big
deal.
It does mean that you have to be careful not to call isLocalId,
isDataConId etc, because they consult the IdInfo of an Id, which
in turn may be determined by the loop-tied unf_env.https://gitlab.haskell.org/ghc/ghc/-/commit/ade2eac4257679a3ac152a39df87ce8567bd7766[project @ 2001-01-30 09:53:11 by simonpj]2001-01-30T09:53:12+00:00simonpjunknownMore on functional dependencies
My last commit allowed this:
instance C a b => C [a] [b] where ...
if we have
class C a b | a -> b
This commit completes the change, by making the
improvement stages improve only the 'shape' of the second
argument of C.
I also had to change the iteration in TcSimplify -- see
the comments in TcSimplify.inferLoop.