-import CoreUtils ( coreExprType, escErrorMsg, mkCoreIfThenElse, mkErrorApp )
-import PrelInfo ( stringTy )
-import Id ( idType, getInstantiatedDataConSig, mkTupleCon,
- DataCon(..), DictVar(..), Id(..), GenId )
-import TyCon ( mkTupleTyCon )
-import Type ( mkTyVarTys, mkRhoTy, mkFunTys,
- applyTyCon, getAppDataTyCon )
-import UniqSet ( mkUniqSet, minusUniqSet, uniqSetToList, UniqSet(..) )
-import Util ( panic, assertPanic )
-
-isUnboxedDataType = panic "DsUtils.isUnboxedDataType"
-quantifyTy = panic "DsUtils.quantifyTy"
-splitDictType = panic "DsUtils.splitDictType"
-mkCoTyApps = panic "DsUtils.mkCoTyApps"
+import CoreUtils ( exprType, mkIfThenElse )
+import PrelInfo ( iRREFUT_PAT_ERROR_ID )
+import MkId ( rebuildConArgs )
+import Id ( idType, Id, mkWildId )
+import Literal ( Literal(..), inIntRange, tARGET_MAX_INT )
+import TyCon ( isNewTyCon, tyConDataCons, isRecursiveTyCon )
+import DataCon ( DataCon, dataConStrictMarks, dataConId )
+import Type ( mkFunTy, isUnLiftedType, Type )
+import TcType ( tcTyConAppTyCon, isIntTy, isFloatTy, isDoubleTy )
+import TysPrim ( intPrimTy, charPrimTy, floatPrimTy, doublePrimTy )
+import TysWiredIn ( nilDataCon, consDataCon,
+ tupleCon,
+ unitDataConId, unitTy,
+ charTy, charDataCon,
+ intDataCon, smallIntegerDataCon,
+ floatDataCon,
+ doubleDataCon,
+ stringTy
+ )
+import BasicTypes ( Boxity(..) )
+import UniqSet ( mkUniqSet, minusUniqSet, isEmptyUniqSet, UniqSet )
+import PrelNames ( unpackCStringName, unpackCStringUtf8Name,
+ plusIntegerName, timesIntegerName )
+import Outputable
+import UnicodeUtil ( stringToUtf8 )
+import Util ( isSingleton )
+\end{code}
+
+
+
+%************************************************************************
+%* *
+\subsection{Tidying lit pats}
+%* *
+%************************************************************************
+
+\begin{code}
+tidyLitPat :: HsLit -> TypecheckedPat -> TypecheckedPat
+tidyLitPat (HsChar c) pat = ConPat charDataCon charTy [] [] [LitPat (HsCharPrim c) charPrimTy]
+tidyLitPat lit pat = pat
+
+tidyNPat :: HsLit -> Type -> TypecheckedPat -> TypecheckedPat
+tidyNPat (HsString s) _ pat
+ | _LENGTH_ s <= 1 -- Short string literals only
+ = foldr (\c pat -> ConPat consDataCon stringTy [] [] [mk_char_lit c,pat])
+ (ConPat nilDataCon stringTy [] [] []) (_UNPK_INT_ s)
+ -- The stringTy is the type of the whole pattern, not
+ -- the type to instantiate (:) or [] with!
+ where
+ mk_char_lit c = ConPat charDataCon charTy [] [] [LitPat (HsCharPrim c) charPrimTy]
+
+tidyNPat lit lit_ty default_pat
+ | isIntTy lit_ty = ConPat intDataCon lit_ty [] [] [LitPat (mk_int lit) intPrimTy]
+ | isFloatTy lit_ty = ConPat floatDataCon lit_ty [] [] [LitPat (mk_float lit) floatPrimTy]
+ | isDoubleTy lit_ty = ConPat doubleDataCon lit_ty [] [] [LitPat (mk_double lit) doublePrimTy]
+ | otherwise = default_pat
+
+ where
+ mk_int (HsInteger i) = HsIntPrim i
+
+ mk_float (HsInteger i) = HsFloatPrim (fromInteger i)
+ mk_float (HsRat f _) = HsFloatPrim f
+
+ mk_double (HsInteger i) = HsDoublePrim (fromInteger i)
+ mk_double (HsRat f _) = HsDoublePrim f
+\end{code}
+
+
+%************************************************************************
+%* *
+\subsection{Building lets}
+%* *
+%************************************************************************
+
+Use case, not let for unlifted types. The simplifier will turn some
+back again.
+
+\begin{code}
+mkDsLet :: CoreBind -> CoreExpr -> CoreExpr
+mkDsLet (NonRec bndr rhs) body
+ | isUnLiftedType (idType bndr) = Case rhs bndr [(DEFAULT,[],body)]
+mkDsLet bind body
+ = Let bind body
+
+mkDsLets :: [CoreBind] -> CoreExpr -> CoreExpr
+mkDsLets binds body = foldr mkDsLet body binds
+\end{code}
+
+
+%************************************************************************
+%* *
+\subsection{ Selecting match variables}
+%* *
+%************************************************************************
+
+We're about to match against some patterns. We want to make some
+@Ids@ to use as match variables. If a pattern has an @Id@ readily at
+hand, which should indeed be bound to the pattern as a whole, then use it;
+otherwise, make one up.
+
+\begin{code}
+selectMatchVar :: TypecheckedPat -> DsM Id
+selectMatchVar (VarPat var) = returnDs var
+selectMatchVar (AsPat var pat) = returnDs var
+selectMatchVar (LazyPat pat) = selectMatchVar pat
+selectMatchVar other_pat = newSysLocalDs (outPatType other_pat) -- OK, better make up one...