Merge pull request #105 from eagletmt/datacon-type

Show types of data constructors with "browse -d"
This commit is contained in:
Kazu Yamamoto 2013-03-01 05:25:05 -08:00
commit 12bb30b097
2 changed files with 11 additions and 2 deletions

View File

@ -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

View File

@ -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"