From 80676966b96314d50f3d55732a77d98d98fdb64b Mon Sep 17 00:00:00 2001 From: eagletmt Date: Fri, 1 Mar 2013 22:11:02 +0900 Subject: [PATCH] Show types of data constructors with "browse -d" --- Browse.hs | 9 +++++++-- test/BrowseSpec.hs | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Browse.hs b/Browse.hs index 1702fb7..fcb82b8 100644 --- a/Browse.hs +++ b/Browse.hs @@ -13,6 +13,7 @@ import TyCon import Type import Types import Var +import DataCon (dataConRepType) ---------------------------------------------------------------- @@ -59,12 +60,16 @@ processModule minfo = mapM processName names inOtherModule nm = getModuleInfo (nameModule nm) >> lookupGlobalName nm showThing :: TyThing -> Maybe String -showThing (AnId i) = Just $ getOccString i ++ " :: " ++ showOutputable (removeForAlls $ varType i) -showThing (ATyCon t) = unwords . toList <$> tyType t +showThing (AnId i) = Just $ formatType varType i +showThing (ADataCon d) = Just $ formatType dataConRepType d +showThing (ATyCon t) = unwords . toList <$> tyType t where toList t' = t' : getOccString t : map getOccString (tyConTyVars t) showThing _ = Nothing +formatType :: NamedThing a => (a -> Type) -> a -> String +formatType f x = getOccString x ++ " :: " ++ showOutputable (removeForAlls $ f x) + tyType :: TyCon -> Maybe String tyType typ | isAlgTyCon typ diff --git a/test/BrowseSpec.hs b/test/BrowseSpec.hs index 78d308f..26c1394 100644 --- a/test/BrowseSpec.hs +++ b/test/BrowseSpec.hs @@ -17,3 +17,7 @@ spec = do it "lists up symbols with type info in the module" $ do syms <- lines <$> browseModule defaultOptions { detailed = True } "Data.Either" syms `shouldContain` "either :: (a -> c) -> (b -> c) -> Either a b -> c" + + it "lists up data constructors with type info in the module" $ do + syms <- lines <$> browseModule defaultOptions { detailed = True} "Data.Either" + syms `shouldContain` "Left :: a -> Either a b"