From 6be6ca76e9163569ad3bed1441cb9fcfa7df0cec Mon Sep 17 00:00:00 2001 From: Ɓukasz Hanuszczak Date: Wed, 15 Jul 2015 20:31:48 +0200 Subject: Get rid of code duplication in type specialization module. --- .../src/Haddock/Backends/Xhtml/Specialize.hs | 30 +++++++++------------- 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'haddock-api/src/Haddock') diff --git a/haddock-api/src/Haddock/Backends/Xhtml/Specialize.hs b/haddock-api/src/Haddock/Backends/Xhtml/Specialize.hs index a2cb8799..50cce3d5 100644 --- a/haddock-api/src/Haddock/Backends/Xhtml/Specialize.hs +++ b/haddock-api/src/Haddock/Backends/Xhtml/Specialize.hs @@ -47,32 +47,26 @@ specializeTyVarBndrs bndrs typs = bname (KindedTyVar (L _ name) _) = name -sugar :: (NamedThing name, DataId name) => HsType name -> HsType name -sugar = sugarTuples . sugarLists - - -sugarLists :: forall name. (NamedThing name, DataId name) - => HsType name -> HsType name -sugarLists = everywhere $ mkT (sugarListsStep :: HsType name -> HsType name) +sugar :: forall name. (NamedThing name, DataId name) + => HsType name -> HsType name +sugar = + everywhere $ mkT step + where + step :: HsType name -> HsType name + step = sugarTuples . sugarLists -sugarListsStep :: NamedThing name => HsType name -> HsType name -sugarListsStep (HsAppTy (L _ (HsTyVar name)) ltyp) +sugarLists :: NamedThing name => HsType name -> HsType name +sugarLists (HsAppTy (L _ (HsTyVar name)) ltyp) | isBuiltInSyntax name' && strName == "[]" = HsListTy ltyp where name' = getName name strName = occNameString . nameOccName $ name' -sugarListsStep typ = typ - - -sugarTuples :: forall name. (NamedThing name, DataId name) - => HsType name -> HsType name -sugarTuples = everywhere $ - mkT (sugarTuplesStep :: HsType name -> HsType name) +sugarLists typ = typ -sugarTuplesStep :: NamedThing name => HsType name -> HsType name -sugarTuplesStep typ = +sugarTuples :: NamedThing name => HsType name -> HsType name +sugarTuples typ = aux [] typ where aux apps (HsAppTy (L _ ftyp) atyp) = aux (atyp:apps) ftyp -- cgit v1.2.3