summaryrefslogtreecommitdiff
path: root/compiler/prelude/TysWiredIn.lhs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2012-06-13 17:21:09 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2012-06-13 17:21:09 +0100
commit5a8ac0f823c151c062a3f1903574030423bb255c (patch)
tree60c7bbe1091ddba9c404f8024928fcea83480523 /compiler/prelude/TysWiredIn.lhs
parent03f78f0686f048e75d671f2797c8684b71655c49 (diff)
downloadhaskell-5a8ac0f823c151c062a3f1903574030423bb255c.tar.gz
Simplify the implementation of Implicit Parameters
This patch re-implements implicit parameters via a class with a functional dependency: class IP (n::Symbol) a | n -> a where ip :: a This definition is in the library module GHC.IP. Notice how it use a type-literal, so we can have constraints like IP "x" Int Now all the functional dependency machinery works right to make implicit parameters behave as they should. Much special-case processing for implicit parameters can be removed entirely. One particularly nice thing is not having a dedicated "original-name cache" for implicit parameters (the nsNames field of NameCache). But many other cases disappear: * BasicTypes.IPName * IPTyCon constructor in Tycon.TyCon * CIPCan constructor in TcRnTypes.Ct * IPPred constructor in Types.PredTree Implicit parameters remain special in a few ways: * Special syntax. Eg the constraint (IP "x" Int) is parsed and printed as (?x::Int). And we still have local bindings for implicit parameters, and occurrences thereof. * A implicit-parameter binding (let ?x = True in e) amounts to a local instance declaration, which we have not had before. It just generates an implication contraint (easy), but when going under it we must purge any existing bindings for ?x in the inert set. See Note [Shadowing of Implicit Parameters] in TcSimplify * TcMType.sizePred classifies implicit parameter constraints as size-0, as before the change There are accompanying patches to libraries 'base' and 'haddock' All the work was done by Iavor Diatchki
Diffstat (limited to 'compiler/prelude/TysWiredIn.lhs')
-rw-r--r--compiler/prelude/TysWiredIn.lhs41
1 files changed, 1 insertions, 40 deletions
diff --git a/compiler/prelude/TysWiredIn.lhs b/compiler/prelude/TysWiredIn.lhs
index 60518bfd9f..78e1f74b4d 100644
--- a/compiler/prelude/TysWiredIn.lhs
+++ b/compiler/prelude/TysWiredIn.lhs
@@ -72,8 +72,6 @@ module TysWiredIn (
-- * Equality predicates
eqTyCon_RDR, eqTyCon, eqTyConName, eqBoxDataCon,
- -- * Implicit parameter predicates
- mkIPName
) where
#include "HsVersions.h"
@@ -85,7 +83,6 @@ import PrelNames
import TysPrim
-- others:
-import Coercion
import Constants ( mAX_TUPLE_SIZE )
import Module ( Module )
import Type ( mkTyConApp )
@@ -95,7 +92,7 @@ import TyCon
import TypeRep
import RdrName
import Name
-import BasicTypes ( TupleSort(..), tupleSortBoxity, IPName(..),
+import BasicTypes ( TupleSort(..), tupleSortBoxity,
Arity, RecFlag(..), Boxity(..), HsBang(..) )
import ForeignCall
import Unique ( incrUnique, mkTupleTyConUnique,
@@ -254,9 +251,6 @@ pcTyCon is_enum is_rec name cType tyvars cons
pcDataCon :: Name -> [TyVar] -> [Type] -> TyCon -> DataCon
pcDataCon = pcDataConWithFixity False
-pcDataCon' :: Name -> Unique -> [TyVar] -> [Type] -> TyCon -> DataCon
-pcDataCon' = pcDataConWithFixity' False
-
pcDataConWithFixity :: Bool -> Name -> [TyVar] -> [Type] -> TyCon -> DataCon
pcDataConWithFixity infx n = pcDataConWithFixity' infx n (incrUnique (nameUnique n))
-- The Name's unique is the first of two free uniques;
@@ -395,39 +389,6 @@ unboxedPairDataCon :: DataCon
unboxedPairDataCon = tupleCon UnboxedTuple 2
\end{code}
-%************************************************************************
-%* *
-\subsection[TysWiredIn-ImplicitParams]{Special type constructors for implicit parameters}
-%* *
-%************************************************************************
-
-\begin{code}
-mkIPName :: FastString
- -> Unique -> Unique -> Unique -> Unique
- -> IPName Name
-mkIPName ip tycon_u datacon_u dc_wrk_u co_ax_u = name_ip
- where
- name_ip = IPName tycon_name
-
- tycon_name = mkPrimTyConName ip tycon_u tycon
- tycon = mkAlgTyCon tycon_name
- (liftedTypeKind `mkArrowKind` constraintKind)
- [alphaTyVar]
- Nothing
- [] -- No stupid theta
- (NewTyCon { data_con = datacon,
- nt_rhs = mkTyVarTy alphaTyVar,
- nt_etad_rhs = ([alphaTyVar], mkTyVarTy alphaTyVar),
- nt_co = mkNewTypeCo co_ax_name tycon [alphaTyVar] (mkTyVarTy alphaTyVar) })
- (IPTyCon name_ip)
- NonRecursive
- False
-
- datacon_name = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "IPBox") datacon_u datacon
- datacon = pcDataCon' datacon_name dc_wrk_u [alphaTyVar] [mkTyVarTy alphaTyVar] tycon
-
- co_ax_name = mkPrimTyConName ip co_ax_u tycon
-\end{code}
%************************************************************************
%* *