Show types of data constructors with "browse -d"
This commit is contained in:
parent
9a6c960d53
commit
80676966b9
@ -13,6 +13,7 @@ import TyCon
|
|||||||
import Type
|
import Type
|
||||||
import Types
|
import Types
|
||||||
import Var
|
import Var
|
||||||
|
import DataCon (dataConRepType)
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
@ -59,12 +60,16 @@ processModule minfo = mapM processName names
|
|||||||
inOtherModule nm = getModuleInfo (nameModule nm) >> lookupGlobalName nm
|
inOtherModule nm = getModuleInfo (nameModule nm) >> lookupGlobalName nm
|
||||||
|
|
||||||
showThing :: TyThing -> Maybe String
|
showThing :: TyThing -> Maybe String
|
||||||
showThing (AnId i) = Just $ getOccString i ++ " :: " ++ showOutputable (removeForAlls $ varType i)
|
showThing (AnId i) = Just $ formatType varType i
|
||||||
|
showThing (ADataCon d) = Just $ formatType dataConRepType d
|
||||||
showThing (ATyCon t) = unwords . toList <$> tyType t
|
showThing (ATyCon t) = unwords . toList <$> tyType t
|
||||||
where
|
where
|
||||||
toList t' = t' : getOccString t : map getOccString (tyConTyVars t)
|
toList t' = t' : getOccString t : map getOccString (tyConTyVars t)
|
||||||
showThing _ = Nothing
|
showThing _ = Nothing
|
||||||
|
|
||||||
|
formatType :: NamedThing a => (a -> Type) -> a -> String
|
||||||
|
formatType f x = getOccString x ++ " :: " ++ showOutputable (removeForAlls $ f x)
|
||||||
|
|
||||||
tyType :: TyCon -> Maybe String
|
tyType :: TyCon -> Maybe String
|
||||||
tyType typ
|
tyType typ
|
||||||
| isAlgTyCon typ
|
| isAlgTyCon typ
|
||||||
|
@ -17,3 +17,7 @@ spec = do
|
|||||||
it "lists up symbols with type info in the module" $ do
|
it "lists up symbols with type info in the module" $ do
|
||||||
syms <- lines <$> browseModule defaultOptions { detailed = True } "Data.Either"
|
syms <- lines <$> browseModule defaultOptions { detailed = True } "Data.Either"
|
||||||
syms `shouldContain` "either :: (a -> c) -> (b -> c) -> Either a b -> c"
|
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"
|
||||||
|
Loading…
Reference in New Issue
Block a user