[commit: ghc] wip/krzysztof-cleanups: Replace nOfThem by replicate (bb1bbbe)

git at git.haskell.org git at git.haskell.org
Tue Mar 19 05:04:28 UTC 2019


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/krzysztof-cleanups
Link       : http://ghc.haskell.org/trac/ghc/changeset/bb1bbbe2e49f2a48623346410d2b2261c158d047/ghc

>---------------------------------------------------------------

commit bb1bbbe2e49f2a48623346410d2b2261c158d047
Author: Krzysztof Gogolewski <krzysztof.gogolewski at tweag.io>
Date:   Mon Mar 18 19:22:10 2019 +0100

    Replace nOfThem by replicate


>---------------------------------------------------------------

bb1bbbe2e49f2a48623346410d2b2261c158d047
 compiler/hsSyn/HsUtils.hs        | 2 +-
 compiler/prelude/TysWiredIn.hs   | 6 +++---
 compiler/typecheck/TcGenDeriv.hs | 4 ++--
 compiler/typecheck/TcHsType.hs   | 6 +++---
 compiler/typecheck/TcMType.hs    | 4 ++--
 compiler/utils/Util.hs           | 5 +----
 6 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/compiler/hsSyn/HsUtils.hs b/compiler/hsSyn/HsUtils.hs
index fa8ec14..ea3c6aa 100644
--- a/compiler/hsSyn/HsUtils.hs
+++ b/compiler/hsSyn/HsUtils.hs
@@ -456,7 +456,7 @@ nlNullaryConPat con = noLoc (ConPatIn (noLoc con) (PrefixCon []))
 
 nlWildConPat :: DataCon -> LPat GhcPs
 nlWildConPat con = noLoc (ConPatIn (noLoc (getRdrName con))
-                         (PrefixCon (nOfThem (dataConSourceArity con)
+                         (PrefixCon (replicate (dataConSourceArity con)
                                              nlWildPat)))
 
 nlWildPat :: LPat GhcPs
diff --git a/compiler/prelude/TysWiredIn.hs b/compiler/prelude/TysWiredIn.hs
index aaeb902..5638b49 100644
--- a/compiler/prelude/TysWiredIn.hs
+++ b/compiler/prelude/TysWiredIn.hs
@@ -870,7 +870,7 @@ mk_tuple Boxed arity = (tycon, tuple_con)
     tycon = mkTupleTyCon tc_name tc_binders tc_res_kind tc_arity tuple_con
                          BoxedTuple flavour
 
-    tc_binders  = mkTemplateAnonTyConBinders (nOfThem arity liftedTypeKind)
+    tc_binders  = mkTemplateAnonTyConBinders (replicate arity liftedTypeKind)
     tc_res_kind = liftedTypeKind
     tc_arity    = arity
     flavour     = VanillaAlgTyCon (mkPrelTyConRepName tc_name)
@@ -895,7 +895,7 @@ mk_tuple Unboxed arity = (tycon, tuple_con)
 
     -- See Note [Unboxed tuple RuntimeRep vars] in TyCon
     -- Kind:  forall (k1:RuntimeRep) (k2:RuntimeRep). TYPE k1 -> TYPE k2 -> #
-    tc_binders = mkTemplateTyConBinders (nOfThem arity runtimeRepTy)
+    tc_binders = mkTemplateTyConBinders (replicate arity runtimeRepTy)
                                         (\ks -> map tYPE ks)
 
     tc_res_kind = unboxedTupleKind rr_tys
@@ -1015,7 +1015,7 @@ mk_sum arity = (tycon, sum_cons)
     -- Unboxed sums are currently not Typeable due to efficiency concerns. See #13276.
     rep_name = Nothing -- Just $ mkPrelTyConRepName tc_name
 
-    tc_binders = mkTemplateTyConBinders (nOfThem arity runtimeRepTy)
+    tc_binders = mkTemplateTyConBinders (replicate arity runtimeRepTy)
                                         (\ks -> map tYPE ks)
 
     tyvars = binderVars tc_binders
diff --git a/compiler/typecheck/TcGenDeriv.hs b/compiler/typecheck/TcGenDeriv.hs
index 4d731db..bb4b643 100644
--- a/compiler/typecheck/TcGenDeriv.hs
+++ b/compiler/typecheck/TcGenDeriv.hs
@@ -687,9 +687,9 @@ gen_Bounded_binds loc tycon
     arity          = dataConSourceArity data_con_1
 
     min_bound_1con = mkHsVarBind loc minBound_RDR $
-                     nlHsVarApps data_con_1_RDR (nOfThem arity minBound_RDR)
+                     nlHsVarApps data_con_1_RDR (replicate arity minBound_RDR)
     max_bound_1con = mkHsVarBind loc maxBound_RDR $
-                     nlHsVarApps data_con_1_RDR (nOfThem arity maxBound_RDR)
+                     nlHsVarApps data_con_1_RDR (replicate arity maxBound_RDR)
 
 {-
 ************************************************************************
diff --git a/compiler/typecheck/TcHsType.hs b/compiler/typecheck/TcHsType.hs
index 489a35c..e0bf255 100644
--- a/compiler/typecheck/TcHsType.hs
+++ b/compiler/typecheck/TcHsType.hs
@@ -889,9 +889,9 @@ tupKindSort_maybe k
 tc_tuple :: HsType GhcRn -> TcTyMode -> TupleSort -> [LHsType GhcRn] -> TcKind -> TcM TcType
 tc_tuple rn_ty mode tup_sort tys exp_kind
   = do { arg_kinds <- case tup_sort of
-           BoxedTuple      -> return (nOfThem arity liftedTypeKind)
-           UnboxedTuple    -> mapM (\_ -> newOpenTypeKind) tys
-           ConstraintTuple -> return (nOfThem arity constraintKind)
+           BoxedTuple      -> return (replicate arity liftedTypeKind)
+           UnboxedTuple    -> replicateM arity newOpenTypeKind
+           ConstraintTuple -> return (replicate arity constraintKind)
        ; tau_tys <- zipWithM (tc_lhs_type mode) tys arg_kinds
        ; finish_tuple rn_ty tup_sort tau_tys arg_kinds exp_kind }
   where
diff --git a/compiler/typecheck/TcMType.hs b/compiler/typecheck/TcMType.hs
index d6a753f..e46cb50 100644
--- a/compiler/typecheck/TcMType.hs
+++ b/compiler/typecheck/TcMType.hs
@@ -148,7 +148,7 @@ newMetaKindVar
        ; return (mkTyVarTy kv) }
 
 newMetaKindVars :: Int -> TcM [TcKind]
-newMetaKindVars n = mapM (\ _ -> newMetaKindVar) (nOfThem n ())
+newMetaKindVars n = replicateM n newMetaKindVar
 
 {-
 ************************************************************************
@@ -944,7 +944,7 @@ newFlexiTyVarTy kind = do
     return (mkTyVarTy tc_tyvar)
 
 newFlexiTyVarTys :: Int -> Kind -> TcM [TcType]
-newFlexiTyVarTys n kind = mapM newFlexiTyVarTy (nOfThem n kind)
+newFlexiTyVarTys n kind = replicateM n (newFlexiTyVarTy kind)
 
 newOpenTypeKind :: TcM TcKind
 newOpenTypeKind
diff --git a/compiler/utils/Util.hs b/compiler/utils/Util.hs
index 6730881..9e67a43 100644
--- a/compiler/utils/Util.hs
+++ b/compiler/utils/Util.hs
@@ -26,7 +26,7 @@ module Util (
 
         mapFst, mapSnd, chkAppend,
         mapAndUnzip, mapAndUnzip3, mapAccumL2,
-        nOfThem, filterOut, partitionWith,
+        filterOut, partitionWith,
 
         dropWhileEndLE, spanEnd, last2, lastMaybe,
 
@@ -458,9 +458,6 @@ mapAccumL2 f s1 s2 xs = (s1', s2', ys)
                                                        (s1', s2', y) -> ((s1', s2'), y))
                                      (s1, s2) xs
 
-nOfThem :: Int -> a -> [a]
-nOfThem n thing = replicate n thing
-
 -- | @atLength atLen atEnd ls n@ unravels list @ls@ to position @n at . Precisely:
 --
 -- @



More information about the ghc-commits mailing list