From 38c8801e397417be75ac4427d9c0a62a7942e0eb Mon Sep 17 00:00:00 2001 From: simonpj Date: Thu, 3 Jul 2003 16:22:17 +0000 Subject: [PATCH] [project @ 2003-07-03 16:22:16 by simonpj] ----------------------- Type defaulting in GHCi ----------------------- [Merge to stable branch, I think.] [Part 2 to this commit: add Eq and Ord, to allow [] == [] at the prompt. Extend type defaulting in GHCi so that ghci> [] [] works. Suggested by Ralf Hinze. --- ghc/compiler/typecheck/TcSimplify.lhs | 7 ++++--- ghc/docs/users_guide/ghci.sgml | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ghc/compiler/typecheck/TcSimplify.lhs b/ghc/compiler/typecheck/TcSimplify.lhs index 31f3255..ff51c42 100644 --- a/ghc/compiler/typecheck/TcSimplify.lhs +++ b/ghc/compiler/typecheck/TcSimplify.lhs @@ -50,10 +50,10 @@ import Id ( idType, mkUserLocal ) import Var ( TyVar ) import Name ( getOccName, getSrcLoc ) import NameSet ( NameSet, mkNameSet, elemNameSet ) -import Class ( classBigSig ) +import Class ( classBigSig, classKey ) import FunDeps ( oclose, grow, improve, pprEquationDoc ) import PrelInfo ( isNumericClass, isCreturnableClass, isCcallishClass ) -import PrelNames ( splitName, fstName, sndName, showClassKey ) +import PrelNames ( splitName, fstName, sndName, showClassKey, eqClassKey, ordClassKey) import HscTypes ( GhciMode(Interactive) ) import Subst ( mkTopTyVarSubst, substTheta, substTy ) @@ -1770,7 +1770,8 @@ disambigGroup ghci_mode dicts std_default_class cls = isNumericClass cls - || (ghci_mode == Interactive && cls `hasKey` showClassKey) + || (ghci_mode == Interactive && + classKey cls `elem` [showClassKey, eqClassKey, ordClassKey]) -- In interactive mode, we default Show a to Show () -- to avoid graututious errors on "show []" diff --git a/ghc/docs/users_guide/ghci.sgml b/ghc/docs/users_guide/ghci.sgml index dfcb955..8fa7ff2 100644 --- a/ghc/docs/users_guide/ghci.sgml +++ b/ghc/docs/users_guide/ghci.sgml @@ -659,7 +659,8 @@ Wed Mar 14 12:23:13 GMT 2001 However, it is tiresome for the user to have to specify the type, so GHCi extends Haskell's type-defaulting rules (Section 4.3.4 of the Haskell 98 Report (Revised)) as follows. If the expression yields a set of type constraints that are all from standard classes (Num, Eq etc.), - and at least one is either a numeric class or the Show class, + and at least one is either a numeric class or the Show, + Eq, or Ord class, GHCi will try to use one of the default types, just as described in the Report. -- 1.7.10.4